[Mono-dev] Reflection: invoking an unsafe constructor/method that declares pointer parameter types
Grégory Pakosz
gpakosz at yahoo.fr
Wed May 2 17:42:41 EDT 2007
hello,
on the windows platform, building a .NET facade to a complex SDK coded
in C, i once had good reasons to use reflection in order to invoke an
unsafe constructor that takes a void* parameter:
public unsafe class SomeClass
{
public SomeClass(void* handle)
{
this.handle = handle;
}
private void* handle;
}
public static void Main(string[] args)
{
ConstructorInfo constructor =
SomeClass.GetConstructor(BindingFlags.Instance|BindingFlags.ExactBinding,null,new
Type[]{typeof(void*)},null);
SomeClass instance = constructor.Invoke(new Object[]{(IntPtr)0});
}
to achieve that, as you can see, i used to use the IntPtr class when
creating the Object[] parameter array that has to be passed to the
ConstructorInfo::Invoke method.
now, i'm trying to achieve the same behavior in Mono: and i get an
ArgumentException because the constructor parameter's do not match;
indeed it seems that IntPtr differs too much from void*.
i know that declaring the constructor as SomeClass(IntPtr handle) would
be an acceptable workaround/solution. however, i was wondering whether
or not Mono should be able to handle such a code, since Microsoft's .NET
accepts it.
more generally, i tried to use google but did not find much information
related to using reflection to invoke unsafe methods that declare
pointers as parameters. how is it supposed to be achieved ? is this
legal ? etc ...
regards,
thanks in advance for any help.
gregory.
More information about the Mono-devel-list
mailing list