2007-11-01 Zoltan Varga <vargaz@gmail.com>
authorZoltan Varga <vargaz@gmail.com>
Thu, 1 Nov 2007 16:31:45 +0000 (16:31 -0000)
committerZoltan Varga <vargaz@gmail.com>
Thu, 1 Nov 2007 16:31:45 +0000 (16:31 -0000)
* Binder.cs: Avoid returning a method with a ParamArray attribute when a normal
method exists. Fixes #338266.

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

mcs/class/corlib/System.Reflection/Binder.cs
mcs/class/corlib/System.Reflection/ChangeLog

index 614aa4dc4e15d99228e7213e9796cf6d715f934b..3ea054c1feb8843176aee8b93a5b73ba71e441d3 100644 (file)
@@ -325,33 +325,39 @@ namespace System.Reflection
                                if (match == null)
                                        throw new ArgumentNullException ("match");
 
+                               /* first look for an exact match... */
+                               for (i = 0; i < match.Length; ++i) {
+                                       m = match [i];
+                                       ParameterInfo[] args = m.GetParameters ();
+                                       if (args.Length != types.Length)
+                                               continue;
+                                       for (j = 0; j < types.Length; ++j) {
+                                               if (types [j] != args [j].ParameterType)
+                                                       break;
+                                       }
+                                       if (j == types.Length)
+                                               return m;
+                               }
+
+                               /* Try methods with ParamArray attribute */
                                bool isdefParamArray = false;
                                Type elementType = null;
-
-                               /* first look for an exact match... */
                                for (i = 0; i < match.Length; ++i) {
                                        m = match [i];
                                        ParameterInfo[] args = m.GetParameters ();
                                        if (args.Length > types.Length)
                                                continue;
-                                       else if(args.Length <= types.Length & args.Length > 0)
-                                       {
-                                               isdefParamArray = Attribute.IsDefined (args [args.Length - 1], typeof (ParamArrayAttribute));
-                                               if (isdefParamArray)
-                                                       elementType = args [args.Length - 1].ParameterType.GetElementType ();
-                                               if (args.Length != types.Length & !isdefParamArray)
-                                                       continue;
-                                       }else if(args.Length == 0 & types.Length > 0)
+                                       else if (args.Length == 0)
+                                               continue;
+                                       isdefParamArray = Attribute.IsDefined (args [args.Length - 1], typeof (ParamArrayAttribute));
+                                       if (!isdefParamArray)
                                                continue;
+                                       elementType = args [args.Length - 1].ParameterType.GetElementType ();
                                        for (j = 0; j < types.Length; ++j) {
-                                               if (!isdefParamArray && types [j] != args [j].ParameterType)
+                                               if (j < (args.Length - 1) && types [j] != args [j].ParameterType)
+                                                       break;
+                                               else if (j >= (args.Length - 1) && types [j] != elementType) 
                                                        break;
-                                               else if (isdefParamArray) {
-                                                       if (j < (args.Length - 1) && types [j] != args [j].ParameterType)
-                                                               break;
-                                                       else if (j >= (args.Length - 1) && types [j] != elementType) 
-                                                               break;
-                                               }
                                        }
                                        if (j == types.Length)
                                                return m;
index 6dbc0ba9be9aebe41f78504fc74cc25796ec252e..8e04ff1d9feb48f196c974466812a250254091de 100644 (file)
@@ -1,3 +1,8 @@
+2007-11-01  Zoltan Varga  <vargaz@gmail.com>
+
+       * Binder.cs: Avoid returning a method with a ParamArray attribute when a normal
+       method exists. Fixes #338266.
+
 2007-10-30  Zoltan Varga  <vargaz@gmail.com>
 
        * Binder.cs: Applied patch from Mario A Chavez <mario.chavez@gmail.com>. Add