[Mono-dev] Patch to add support to execute methods with ParamArray thought Reflection

Mario Chavez mario.chavez at gmail.com
Wed Oct 24 15:47:22 EDT 2007


Hi;

Currently reflection does not support methods that have ParamArray attribute
to be called with InvokeMember, like:

... some class
public static void TestMethod(params string[] param1)
    {
        Console.WriteLine("Test Method 3, one params");
    }
.... some class

Type type = typeof(ParamArrayTest);
        object obj = type.InvokeMember("TestMethod", InvokeBindingFlags,
null, null, new object[] {"param1"});

it fails with:

Unhandled Exception: System.MissingMethodException: The best match for
method TestMethod has some invalid parameter.
  at System.MonoType.InvokeMember (System.String name, BindingFlags
invokeAttr, System.Reflection.Binder binder, System.Object target,
System.Object[] args, System.Reflection.ParameterModifier[] modifiers,
System.Globalization.CultureInfo culture, System.String[] namedParameters)
[0x00000]
  at System.Type.InvokeMember (System.String name, BindingFlags invokeAttr,
System.Reflection.Binder binder, System.Object target, System.Object[] args)
[0x00000]
  at ParamArrayTest.Main (System.String[] args) [0x00000]

This patch for Binder.cs and MonoType.cs allows this type of calling, which
by the way does work on MS .NET

I hope that this patch is good enough to go into Mono

Thanks
-- 
Mario Chavez
mario.chavez at gmail.com
http://mario-chavez.blogspot.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20071024/1dfafb77/attachment.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: paramarray.diff
Type: application/octet-stream
Size: 4104 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20071024/1dfafb77/attachment.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ParamArrayTest.cs
Type: application/octet-stream
Size: 1102 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20071024/1dfafb77/attachment-0001.obj 


More information about the Mono-devel-list mailing list