diff --git a/src/ExpressionExtensions.cs b/src/ExpressionExtensions.cs index f88cb26..ccf9c7a 100644 --- a/src/ExpressionExtensions.cs +++ b/src/ExpressionExtensions.cs @@ -7,7 +7,7 @@ internal static class ExpressionExtensions private const string JsIndicationStart = "HYDRO_JS("; private const string JsIndicationEnd = ")HYDRO_JS"; - public static (string Name, IDictionary Parameters)? GetNameAndParameters(this Expression expression) + public static (string Name, IDictionary Parameters)? GetNameAndParameters(this LambdaExpression expression) { if (expression is not { Body: MethodCallExpression methodCall }) { @@ -40,7 +40,7 @@ internal static object EvaluateExpressionValue(Expression expression) { case ConstantExpression constantExpression: return constantExpression.Value; - + case MemberExpression memberExpression: var objectMember = Expression.Convert(memberExpression, typeof(object)); var getterLambda = Expression.Lambda>(objectMember); diff --git a/src/TagHelpers/HydroOnTagHelper.cs b/src/TagHelpers/HydroOnTagHelper.cs index ca9fd33..dc993bf 100644 --- a/src/TagHelpers/HydroOnTagHelper.cs +++ b/src/TagHelpers/HydroOnTagHelper.cs @@ -16,13 +16,13 @@ public sealed class HydroOnTagHelper : TagHelper { private const string HandlersPrefix = "hydro-on:"; - private IDictionary> _handlers; + private IDictionary _handlers; /// [HtmlAttributeName(DictionaryAttributePrefix = HandlersPrefix)] - public IDictionary> Handlers + public IDictionary Handlers { - get => _handlers ??= new Dictionary>(StringComparer.OrdinalIgnoreCase); + get => _handlers ??= new Dictionary(StringComparer.OrdinalIgnoreCase); set => _handlers = value; } @@ -52,7 +52,12 @@ public override void Process(TagHelperContext context, TagHelperOutput output) foreach (var eventItem in _handlers) { - var jsExpression = GetJsExpression(eventItem.Value); + if (eventItem.Value is not LambdaExpression actionExpression) + { + throw new InvalidOperationException($"Wrong event handler statement in component for {modelType.Namespace}"); + } + + var jsExpression = GetJsExpression(actionExpression); if (jsExpression == null) { @@ -70,7 +75,7 @@ public override void Process(TagHelperContext context, TagHelperOutput output) } } - private static string GetJsExpression(Expression expression) + private static string GetJsExpression(LambdaExpression expression) { var clientAction = GetJsClientActionExpression(expression); @@ -82,7 +87,7 @@ private static string GetJsExpression(Expression expression) return GetJsInvokeExpression(expression); } - private static string GetJsClientActionExpression(Expression expression) + private static string GetJsClientActionExpression(LambdaExpression expression) { if (expression is not { Body: MethodCallExpression methodCall } || methodCall.Method.DeclaringType != typeof(HydroClientActions)) @@ -101,7 +106,7 @@ private static string GetJsClientActionExpression(Expression expression) } } - private static string GetJsInvokeExpression(Expression expression) + private static string GetJsInvokeExpression(LambdaExpression expression) { var eventData = expression.GetNameAndParameters();