2008-03-05 Jb Evain <jbevain@novell.com>
authorJb Evain <jbevain@gmail.com>
Wed, 5 Mar 2008 22:09:43 +0000 (22:09 -0000)
committerJb Evain <jbevain@gmail.com>
Wed, 5 Mar 2008 22:09:43 +0000 (22:09 -0000)
* Expression.cs: Fix the Call method which takes an array
of type arguments.

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

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

index 100b6bf01669a3d5db94606d93af396a55995ffa..399649e326a4b5ba5d8cc3a42124894b170031c8 100644 (file)
@@ -1,3 +1,8 @@
+2008-03-05  Jb Evain  <jbevain@novell.com>
+
+       * Expression.cs: Fix the Call method which takes an array
+       of type arguments.
+
 2008-03-05  Jb Evain  <jbevain@novell.com>
 
        * Expression.cs: fix for a good chunk of lifted/liftToNull tests.
index b14b93a4bf74e4fd73627f1df2b893f0d71ac60d..d24322901d8a585964e76affb0b1370ee726374a 100644 (file)
@@ -902,6 +902,25 @@ namespace System.Linq.Expressions {
                        return new MethodCallExpression (instance, method, args);
                }
 
+               static Type [] CollectTypes (IEnumerable<Expression> expressions)
+               {
+                       return (from arg in expressions select arg.Type).ToArray ();
+               }
+
+               static MethodInfo TryMakeGeneric (MethodInfo method, Type [] args)
+               {
+                       if (method == null)
+                               return null;
+
+                       if (!method.IsGenericMethod && args == null)
+                               return method;
+
+                       if (args.Length == method.GetGenericArguments ().Length)
+                               return method.MakeGenericMethod (args);
+
+                       return null;
+               }
+
                public static MethodCallExpression Call (Expression instance, string methodName, Type [] typeArguments, params Expression [] arguments)
                {
                        if (instance == null)
@@ -909,10 +928,8 @@ namespace System.Linq.Expressions {
                        if (methodName == null)
                                throw new ArgumentNullException ("methodName");
 
-                       if (typeArguments == null)
-                               typeArguments = (from arg in arguments select arg.Type).ToArray ();
-
-                       var method = instance.Type.GetMethod (methodName, AllInstance, null, typeArguments, null);
+                       var method = instance.Type.GetMethod (methodName, AllInstance, null, CollectTypes (arguments), null);
+                       method = TryMakeGeneric (method, typeArguments);
                        if (method == null)
                                throw new InvalidOperationException ("No such method");
 
@@ -929,10 +946,8 @@ namespace System.Linq.Expressions {
                        if (methodName == null)
                                throw new ArgumentNullException ("methodName");
 
-                       if (typeArguments == null)
-                               typeArguments = (from arg in arguments select arg.Type).ToArray ();
-
-                       var method = type.GetMethod (methodName, AllStatic, null, typeArguments, null);
+                       var method = type.GetMethod (methodName, AllStatic, null, CollectTypes (arguments), null);
+                       method = TryMakeGeneric (method, typeArguments);
                        if (method == null)
                                throw new InvalidOperationException ("No such method");