2006-05-08 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Mon, 8 May 2006 14:45:08 +0000 (14:45 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Mon, 8 May 2006 14:45:08 +0000 (14:45 -0000)
* Binder.cs : (DefaultBinder.BindToMethod) reorder parameters based
  on namedParameters. Fixed bug #41691.

* BinderTests.cs : added test for bug #41691.

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

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

index a399459ee9ad7a4a7bcf03f27c2ce6a7967e64d1..40e7eaaf910e7ecdc4b4551cd593856c6c6dd6b4 100644 (file)
@@ -141,9 +141,25 @@ namespace System.Reflection
                                }
                                MethodBase selected = SelectMethod (bindingAttr, match, types, modifiers);
                                state = null;
+                               if (names != null)
+                                       ReorderParameters (names, ref args, selected);
                                return selected;
                        }
 
+                       void ReorderParameters (string [] names, ref object [] args, MethodBase selected)
+                       {
+                               ParameterInfo [] plist = selected.GetParameters ();
+                               for (int n = 0; n < names.Length; n++)
+                                       for (int p = 0; p < plist.Length; p++) {
+                                               if (names [n] == plist [p].Name) {
+                                                       object o = args [n];
+                                                       args [n] = args [p];
+                                                       args [p] = o;
+                                               }
+                                               break;
+                                       }
+                       }
+
                        static bool IsArrayAssignable (Type object_type, Type target_type)
                        {
                                if (object_type.IsArray && target_type.IsArray)
index ea473f78e3ca2d1d3d131654d03cb87e25833880..7574ed7ed3b1ce17f887aad5a9b81c75ce6c89f5 100644 (file)
@@ -1,3 +1,8 @@
+2006-05-08  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * Binder.cs : (DefaultBinder.BindToMethod) reorder parameters based
+         on namedParameters. Fixed bug #41691.
+
 2006-05-03  Jb Evain  <jbevain@gmail.com>
 
        * MonoField.cs (GetValue,SetValue): throw a TargetException
index 4d35d3dcdc91ee3c8114601248524b8ab4a37240..95515d18ce1e1c9d5587f0f3295af0d386c15305 100644 (file)
@@ -9,6 +9,7 @@
 
 using NUnit.Framework;
 using System;
+using System.IO;
 using System.Reflection;
 
 namespace MonoTests.System.Reflection
@@ -221,6 +222,39 @@ namespace MonoTests.System.Reflection
                        PropertyInfo prop = binder.SelectProperty (0, props, null, new Type [] {null}, null);
                        Assert.IsNotNull (prop);
                }
+
+               [Test] // bug #41691
+               public void BindToMethodNamedArgs ()
+               {
+                       Type t = typeof (Bug41691);
+
+                       StringWriter sw = new StringWriter ();
+                       sw.NewLine = "\n";
+
+                       object[] argValues = new object [] {"Hello", "World", "Extra", sw};
+                       string [] argNames = new string [] {"firstName", "lastName"};
+
+                       t.InvokeMember ("PrintName",
+                                       BindingFlags.InvokeMethod,
+                                       null,
+                                       null,
+                                       argValues,
+                                       null,
+                                       null,
+                                       argNames);
+
+                       Assert.AreEqual ("Hello\nExtra\nWorld", sw.ToString ());
+               }
+
+               public class Bug41691
+               {
+                       public static void PrintName (string lastName, string firstName, string extra, TextWriter output)
+                       {
+                               output.WriteLine (firstName);
+                               output.WriteLine (extra);
+                               output.WriteLine (lastName);
+                       }
+               }
        }
 }
 
index 536025bd48cab90ad3f34eb5e8e5008d529955b6..623fd384cd98e5960caf518e42135c22ca3549d6 100644 (file)
@@ -1,3 +1,7 @@
+2006-05-08  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * BinderTests.cs : added test for bug #41691.
+
 2006-03-09  Zoltan Varga  <vargaz@gmail.com>
 
        * MethodInfoTest.cs: Add test for #77668.