[Mono-dev] Detect List<> from C code
Robert Jordan
robertj at gmx.net
Sat Jun 20 09:30:28 EDT 2009
Joachim Ante wrote:
> Hi,
>
> Whats the best way of checking if a MonoField* refers to a
> System.Generic.Container.List<>? The check needs to be high performance.
The public API does not expose the necessary functions to
achieve this, but you could use a managed helper:
public static bool IsGenericTypeOf (Type genericInstance, Type
genericDefinition)
{
if (!genericInstance.IsGenericType)
return false;
if (!genericDefinition.IsGenericTypeDefinition)
return false;
return genericInstance.GetGenericTypeDefinition() ==
genericDefinition;
}
When you invoke this method, the type arguments are actually
MonoReflectionType*s which you can get from a class using
this code:
mono_type_get_object(mono_class_get_type (class))
Robert
More information about the Mono-devel-list
mailing list