From: Jb Evain Date: Wed, 5 Mar 2008 22:09:43 +0000 (-0000) Subject: 2008-03-05 Jb Evain X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=e1fd90ecb78c8a7516a9b7bd30c37f788d5bedbb;p=mono.git 2008-03-05 Jb Evain * Expression.cs: Fix the Call method which takes an array of type arguments. svn path=/trunk/mcs/; revision=97456 --- diff --git a/mcs/class/System.Core/System.Linq.Expressions/ChangeLog b/mcs/class/System.Core/System.Linq.Expressions/ChangeLog index 100b6bf0166..399649e326a 100644 --- a/mcs/class/System.Core/System.Linq.Expressions/ChangeLog +++ b/mcs/class/System.Core/System.Linq.Expressions/ChangeLog @@ -1,3 +1,8 @@ +2008-03-05 Jb Evain + + * Expression.cs: Fix the Call method which takes an array + of type arguments. + 2008-03-05 Jb Evain * Expression.cs: fix for a good chunk of lifted/liftToNull tests. diff --git a/mcs/class/System.Core/System.Linq.Expressions/Expression.cs b/mcs/class/System.Core/System.Linq.Expressions/Expression.cs index b14b93a4bf7..d24322901d8 100644 --- a/mcs/class/System.Core/System.Linq.Expressions/Expression.cs +++ b/mcs/class/System.Core/System.Linq.Expressions/Expression.cs @@ -902,6 +902,25 @@ namespace System.Linq.Expressions { return new MethodCallExpression (instance, method, args); } + static Type [] CollectTypes (IEnumerable 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");