/// <summary> /// An invokation. Attempt to decode the Compile from an Expression. Support the normal ".NET" way of doing things /// as opposed to the "invoke" method above (which has a slightly cleaner syntax, but not much!). /// </summary> /// <param name="expression"></param> /// <returns></returns> public Expression Transform(InvocationExpression expression) { // // Fail quickly looking for the call // if (expression.Expression.NodeType != ExpressionType.Call) { return(expression); } var callExpr = expression.Expression as MethodCallExpression; if (callExpr.Object == null) { return(expression); } if (!typeof(Expression).IsAssignableFrom(callExpr.Object.Type)) { return(expression); } if (callExpr.Method.Name != "Compile") { return(expression); } // // Now, pick a part the expression type and make sure it is a func! // var exprFinder = new ExpressionFunctionExpander(); return(exprFinder.Visit(expression)); }
/// <summary> /// If this is one of our Invoke method calls, then we can try to do expression replacement. /// </summary> /// <param name="expression"></param> /// <returns></returns> public Expression Transform(MethodCallExpression expression) { if (expression == null) { throw new ArgumentNullException("expression"); } // // Fail quickly if this isn't something we are interested in. // if (expression.Object != null || expression.Method.Name != "Invoke") { return(expression); } if (expression.Method.DeclaringType != typeof(Helpers)) { return(expression); } // // Ok, this is real. Get the expression. The compiler should make sure that // all types match properly. // var exprFinder = new ExpressionFunctionExpander(); var expanded = exprFinder.Visit(expression); var result = new PartialEvaluatingExpressionTreeProcessor(new EvaluatableExpressionFilterAll()).Process(expanded); return(result); }