[Mono-list] Obtaining a generic MonoMethod

Andreas Färber andreas.faerber at web.de
Sun Dec 3 19:33:29 EST 2006


Hi Robert,

>> I would like to invoke the generic method IList<T>.Add(T) on an
>> object - how can I do this?
>>
>> I've been able to get a MonoClass of "IList`1" but neither using
>> mono_class_get_method_from_name nor using a MonoMethodDesc did I
>> succeed in retrieving a non-zero MonoMethod*.
>
> Unlike System.Collections.IList, System.Collections.IList`1
> doesn't define the member "Add". ICollection`1 does it.

Sorry, must have mixed up the doc pages then.

Still, obtaining a non-zero ICollection`1 MonoClass*, I get a non- 
zero mono_class_get_method_from_name(cls, "Add", 1) MonoMethod*  
("System.Collections.Generic.ICollection`1:Add (T)") - but then if I  
do mono_object_get_virtual_method, mono_method_full_name on the  
returned MonoMethod* says it's System.Object:Finalize()!
(I personally consider this a bug 'cause if I'm doing something wrong  
I would expect a NULL MonoMethod* instead of a pointer to a method I  
didn't request! Should I file a bug report?)

So please consider it a general question: How do I correctly invoke a  
generic method? ;-)

I'm not bound to a specific way of doing it, all I need for now is to  
invoke this one method in any way that works.
Do I need to use a MonoMethodDesc* with specified T type like  
"System.Collections.Generic.ICollection`1[MyType:Add(what_here?)", or  
do I need to do some post-processing on the generic MonoMethod* once  
I've obtained it through _from_name to fill in the T?

Regards,

Andreas


More information about the Mono-list mailing list