public static object?Execute(this Expression expression, params object[] values) { ExpressionReflectionExecutor visitor = new ExpressionReflectionExecutor(expression); object?result = visitor.Execute(values); return(result); }
protected override Expression VisitLambda <T>(Expression <T> node) { string methodName; Type type = node.Type; if (type.IsFunc()) { methodName = "Func"; } else if (type.IsAction()) { methodName = "Action"; } else if (type.IsPredicate()) { methodName = "Predicate"; } else { throw new ExpressionExecutionException(string.Format("No wrapper method available for delegate type '{0}'", type.Name)); } var executor = new ExpressionReflectionExecutor(node); Type[] genericArguments = type.GenericTypeArguments; MethodInfo?methodInfo = this.FindMethod(methodName, genericArguments); Delegate? @delegate = methodInfo?.CreateDelegate(type, executor); return(this.VisitConstant(Expression.Constant(@delegate))); }