private static Expression BuildStaticMethodExpression(MemberInfo member, Expression[] arguments) { var method = member as MethodInfo; if (method == null || !method.IsStatic) { return(null); } arguments = arguments.Zip(method.GetParameters(), (a, p) => CastExpressionBuilder.Build(p.ParameterType, a)) .ToArray(); return(Expression.Call(null, method, arguments)); }
private static Expression BuildMemberMethodExpression(MemberInfo member, Expression[] arguments) { var method = member as MethodInfo; if (method == null || method.IsStatic) { return(null); } var instance = arguments.First(); arguments = arguments.Skip(1).Zip(method.GetParameters(), (a, p) => new { Argument = a, CastTo = p.ParameterType }) .Select(x => CastExpressionBuilder.Build(x.CastTo, x.Argument)) .ToArray(); return(Expression.Call(instance, method, arguments)); }