private static MethodCallCSharpExpression MakeAccess(ConditionalReceiver receiver, MethodInfo method, ReadOnlyCollection <ParameterAssignment> arguments) { if (method.IsStatic && method.IsDefined(typeof(ExtensionAttribute))) { var thisPar = method.GetParametersCached()[0]; var thisArg = CSharpExpression.Bind(thisPar, receiver); var newArgs = new ParameterAssignment[arguments.Count + 1]; newArgs[0] = thisArg; var i = 1; foreach (var arg in arguments) { newArgs[i++] = arg; } var newArguments = new TrueReadOnlyCollection <ParameterAssignment>(newArgs); return(CSharpExpression.Call(null, method, newArguments)); // TODO: call ctor directly } else { return(CSharpExpression.Call(receiver, method, arguments)); // TODO: call ctor directly } }
/// <summary> /// Creates a new expression that is like this one, but using the supplied children. If all of the children are the same, it will return this expression. /// </summary> /// <param name="expression">The <see cref="Expression" /> property of the result.</param> /// <returns>This expression if no children changed, or an expression with the updated children.</returns> public ParameterAssignment Update(Expression expression) { if (expression == Expression) { return(this); } return(CSharpExpression.Bind(Parameter, expression)); }
public static ReadOnlyCollection <ParameterAssignment> GetParameterBindings(ParameterInfo[] parameters, IEnumerable <Expression> expressions) { var arguments = expressions.ToReadOnly(); var n = arguments.Count; if (n > parameters.Length) { throw Error.TooManyArguments(); } var bindings = new ParameterAssignment[n]; for (var i = 0; i < n; i++) { bindings[i] = CSharpExpression.Bind(parameters[i], arguments[i]); } return(new TrueReadOnlyCollection <ParameterAssignment>(bindings)); }