2008-01-29 Jb Evain <jbevain@novell.com>
authorJb Evain <jbevain@gmail.com>
Tue, 29 Jan 2008 12:51:11 +0000 (12:51 -0000)
committerJb Evain <jbevain@gmail.com>
Tue, 29 Jan 2008 12:51:11 +0000 (12:51 -0000)
* MethodCallExpression.cs, Expression.cs: complete Calls.

svn path=/trunk/mcs/; revision=94240

mcs/class/System.Core/System.Linq.Expressions/ChangeLog
mcs/class/System.Core/System.Linq.Expressions/Expression.cs
mcs/class/System.Core/System.Linq.Expressions/MethodCallExpression.cs

index 5f89ee4cf6e5cd880c78307391f08cb8117ee49f..709151eff0fc43a47e400659bedbf1fd5f62b065 100644 (file)
@@ -1,3 +1,7 @@
+2008-01-29  Jb Evain  <jbevain@novell.com>
+
+       * MethodCallExpression.cs, Expression.cs: complete Calls.
+
 2008-01-29  Jb Evain  <jbevain@novell.com>
 
        * Expression.cs, NewExpression.cs, ExpressionPrinter.cs:
index cc165a218c3e036e80681643f7f311d39440272f..db6a8134c73b1120081b765c7df8947f43ccf6f3 100644 (file)
@@ -933,16 +933,46 @@ namespace System.Linq.Expressions {
                        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)
index 087c14bbb721f03704026ef8a331e4f8fe36a025..55c493520af9fe156e94b36762f2460b09717f60 100644 (file)
@@ -34,12 +34,12 @@ namespace System.Linq.Expressions {
 
        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 {
@@ -50,10 +50,17 @@ namespace System.Linq.Expressions {
                        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;
                }