Lambda() public static method

public static Lambda ( Type lambdaType, Expression body, IEnumerable parameterExpression, IScope scope, INRefcatoryExpressionVisitor visitor ) : Lambda
lambdaType Type
body Expression
parameterExpression IEnumerable
scope IScope
visitor INRefcatoryExpressionVisitor
return Lambda
Example #1
0
        public Expression Update(Expression body, Type type, IEnumerable <ParameterExpression> parameters)
        {
            if (Body.Equals(body) && Type.Equals(type) && ReferenceEquals(Parameters, parameters))
            {
                return(this);
            }

            return(AstExpression.Lambda(InternalType, Body, Parameters, ParentScope, Visitor));
        }
        private Expression ReduceBaseAssignment(Base expression)
        {
            Type             returnType       = null;
            Delegate         @delegate        = null;
            MethodInfo       methodInfo       = null;
            ILGenerator      ilGenerator      = null;
            DynamicMethod    dynamicMethod    = null;
            Type             delegateType     = typeof(Func <, ,>);
            MethodDefinition methodDefinition = null;
            var expressionType = expression.Type;
            ParameterExpression assignedValue = null;
            var propertyReference             = _memberReferenceExpression.Annotation <PropertyDefinition>();

            methodDefinition = propertyReference.GetMethod;
            methodInfo       = methodDefinition.GetActualMethod <MethodInfo>();
            returnType       = InternalType = methodInfo.ReturnType;
            assignedValue    = AstExpression.Parameter(returnType);
            methodDefinition = propertyReference.SetMethod;
            methodInfo       = methodDefinition.GetActualMethod <MethodInfo>();

            dynamicMethod = new DynamicMethod(string.Format("Base_{0}", methodInfo.Name), returnType, new Type[] { expressionType, returnType }, expressionType);
            ilGenerator   = dynamicMethod.GetILGenerator();
            ilGenerator.Emit(OpCodes.Ldarg_0);
            ilGenerator.Emit(OpCodes.Ldarg_1);
            ilGenerator.EmitCall(OpCodes.Call, methodInfo, null);
            ilGenerator.Emit(OpCodes.Ldarg_1);
            ilGenerator.Emit(OpCodes.Ret);

            delegateType = delegateType.MakeGenericType(expressionType, returnType, returnType);
            @delegate    = dynamicMethod.CreateDelegate(delegateType);

            return(AstExpression.Lambda(
                       AstExpression.GetFuncType(returnType, returnType),
                       AstExpression.Invoke(AstExpression.Constant(@delegate), Expression, assignedValue),
                       new ParameterExpression[] { assignedValue },
                       ParentScope, Visitor));
        }