[Mono-dev] Detect List<> from C code

Joachim Ante joe at unity3d.com
Sun Jun 21 08:50:51 EDT 2009


> > Now i have the generic type from the field in a MonoClass* pointer,
> > how do I correctly create an instance from the class?
>
> If the only thing you have is a List<T>, you cannot create
> a class from it because you need to know the T.
>
> But if your field's class is a *closed* generic type like
> List<int>, then mono_object_new () will work just fine.
>
> Yes, generics is a missing part of the embedding API and this is
> something to be addressed. One should be able to do things like
> get the instantiation vector or create a new instantation.
Hmm, so I have:

class MyClass
{
     List<int> a;
}

I iterate through it from c code and use mono_class_get_fields,  
mono_class_from_mono_type(mono_field_get_type(field))

Then i do mono_object_new and call mono_runtime_object_init on it.

Are you sure this should work? It generates an invalid object for me.  
Is it possible that using System.Activator.CreateInstance  will  work  
better or does this internally do the exact same thing?

Joachim Ante
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20090621/70ba4934/attachment.html 


More information about the Mono-devel-list mailing list