[Mono-dev] MonoListWrapper WIP - code review/feedback
Robert Jordan
robertj at gmx.net
Sat Jul 20 15:28:28 UTC 2013
On 20.07.2013 12:03, rfine at tbrf.net wrote:
> 2) Using mono_class_get_generic_class(),
> mono_generic_class_get_context(), and the MonoGenericContext structure
> to retrieve the List<T> generic type argument:
>
> I can't find any public API for retrieving info about a generic
> instantiation. There's a couple of methods for checking whether
> something *is* inflated, but nothing for retrieving or working with the
> MonoGenericContext that it was inflated *with*. So I'm not sure what to
> change this to. Any suggestions?
This is no public API for this, but you can always use the
managed reflection API:
1) get the MonoReflectionType* (the unmanaged representation of
a System.Type object) of the MonoType* of the class using
mono_type_get_object
2) invoke Type.GenericArguments() on this MonoReflectionType*.
Unfortunately, you'll hit the next read block after (2). There is
no public way to get a MonoType* from MonoReflectionType*, so you
have to implement a C# helper for (2):
/*
* gets the MonoTypes* of the generic arguments of the specified Type.
*/
static IntPtr[] GenericArguments(Type type)
{
/* FIXME: check that "type" is a closed generic type */
var types = t.GetGenericArguments(type);
var handles = new IntPtr[types.Length];
for (int i = 0; i < types.Length; i++)
handles [i] = types[i].TypeHandle.Value;
return handles;
}
But, according to
https://github.com/richard-fine/mono/blob/MonoListWrapper/contrib/MonoListWrapper/MonoListWrapper.c#L34
it looks like you don't need this stuff at all :)
You can obtain the element class of the array (the "elementType" of
your wrapper) with mono_class_get_element_class () invoked
on the class of the "_items" field of the List<T> in question.
Robert
More information about the Mono-devel-list
mailing list