Esempio n. 1
0
        private Expression GenerateMethodCall(MethodData method, ArgumentData target, IList <ArgumentData> args)
        {
            args = BindingReflectionExtensions.GetMethodArgs(method.IsExtensionMethod, target, args);
            var expressions = new Expression[args.Count];

            for (int index = 0; index < args.Count; index++)
            {
                var data = args[index];
                if (data.IsLambda)
                {
                    _lambdaParameter = method.Parameters[index];
                    data.UpdateExpression(BuildExpression(data.Node));
                    _lambdaParameter = null;
                }
                expressions[index] = data.Expression;
            }
            var methodInfo = method.Build(args);

            expressions = ConvertParameters(methodInfo, expressions);
            if (method.IsExtensionMethod)
            {
                return(Expression.Call(null, methodInfo, expressions));
            }
            return(Expression.Call(target.Expression, methodInfo, expressions));
        }