[Mono-list] Obtaining a generic MonoMethod

Robert Jordan robertj at gmx.net
Tue Dec 5 07:11:56 EST 2006


Hi Andreas,

Andreas Färber wrote:
>>> So please consider it a general question: How do I correctly invoke a
>>> generic method? ;-)
>>
>> You call methods of generic classes like every other method.
>> The "trick" is to get the method from the "inflated" class,
>> which you can obtain from mono_object_get_class ().
>>
>> MonoClass *clazz = mono_object_get_class (obj);
> 
> I'm not so happy with this solution. I thought of this but it's not as 
> simple as that! ;-)
> 
> I figured out I always have to use the exact MonoClass the method is 
> declared on. So the above solution will only work if the MonoClass 
> returned by mono_object_get_class was in fact the one implementing the 
> correct method (as opposed to e.g.: ICollection<T> -> 
> IList<T>:ICollection<T> -> OneClass:IList<MyType> -> 
> AnotherClass:OneClass), also this messes with overridden/new methods as 
> I wouldn't be using mono_object_get_virtual_method that way.

That's the way it currently works.

> The documentation has some names of functions surrounding generics but 
> they're not really documented:

They are not exposed via the embedded API, like many of the generics
features (object creation), but System.Reflection could be used
instead.

Robert



More information about the Mono-list mailing list