[Mono-dev] Reflection: invoking an unsafe constructor/method that declares pointer parameter types

Paolo Molaro lupus at ximian.com
Thu May 3 11:25:58 EDT 2007


On 05/02/07 Grégory Pakosz wrote:
> 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});
> }
> 
[...]
> 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 ...

Could you please file a bug in bugzilla with a complete test case?
Thanks.

lupus

-- 
-----------------------------------------------------------------
lupus at debian.org                                     debian/rules
lupus at ximian.com                             Monkeys do it better



More information about the Mono-devel-list mailing list