}
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)
+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
using NUnit.Framework;
using System;
+using System.IO;
using System.Reflection;
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);
+ }
+ }
}
}