return new MethodCallExpression (instance, method, args);
}
- [MonoTODO]
public static MethodCallExpression Call (Expression instance, string methodName, Type [] typeArguments, params Expression [] arguments)
{
- throw new NotImplementedException ();
+ if (instance == null)
+ throw new ArgumentNullException ("instance");
+ if (methodName == null)
+ throw new ArgumentNullException ("methodName");
+
+ if (typeArguments == null)
+ typeArguments = new Type [0];
+
+ var method = instance.Type.GetMethod (methodName, AllInstance, null, typeArguments, null);
+ if (method == null)
+ throw new InvalidOperationException ("No such method");
+
+ var args = arguments.ToReadOnlyCollection ();
+ if (typeArguments.Length != args.Count)
+ throw new InvalidOperationException ("Argument count doesn't match parameters length");
+
+ return new MethodCallExpression (instance, method, args);
}
- [MonoTODO]
public static MethodCallExpression Call (Type type, string methodName, Type [] typeArguments, params Expression [] arguments)
{
- throw new NotImplementedException ();
+ if (type == null)
+ throw new ArgumentNullException ("type");
+ if (methodName == null)
+ throw new ArgumentNullException ("methodName");
+
+ if (typeArguments == null)
+ typeArguments = new Type [0];
+
+ var method = type.GetMethod (methodName, AllStatic, null, typeArguments, null);
+ if (method == null)
+ throw new InvalidOperationException ("No such method");
+
+ var args = arguments.ToReadOnlyCollection ();
+ if (typeArguments.Length != args.Count)
+ throw new InvalidOperationException ("Argument count doesn't match parameters length");
+
+ return new MethodCallExpression (method, args);
}
public static ConditionalExpression Condition (Expression test, Expression ifTrue, Expression ifFalse)
public sealed class MethodCallExpression : Expression {
- Expression @object;
+ Expression obj;
MethodInfo method;
ReadOnlyCollection<Expression> arguments;
public Expression Object {
- get { return @object; }
+ get { return obj; }
}
public MethodInfo Method {
get { return arguments; }
}
- internal MethodCallExpression (Expression @object, MethodInfo method, ReadOnlyCollection<Expression> arguments)
+ internal MethodCallExpression (MethodInfo method, ReadOnlyCollection<Expression> arguments)
: base (ExpressionType.Call, method.ReturnType)
{
- this.@object = @object;
+ this.method = method;
+ this.arguments = arguments;
+ }
+
+ internal MethodCallExpression (Expression obj, MethodInfo method, ReadOnlyCollection<Expression> arguments)
+ : base (ExpressionType.Call, method.ReturnType)
+ {
+ this.obj = obj;
this.method = method;
this.arguments = arguments;
}