public static int GetTypeGenerity(IType type)
{
if (type.IsByRef || type.IsArray)
return GetTypeGenerity(type.ElementType);
if (type is IGenericParameter)
return 1;
// Generic parameters and generic arguments both contribute
// to a types genrity. Note that a nested type can be both a generic definition
// and a constructed type: Outer[of int].Inner[of T]
int generity = 0;
if (type.GenericInfo != null)
generity += type.GenericInfo.GenericParameters.Length;
if (type.ConstructedInfo != null)
foreach (IType typeArg in type.ConstructedInfo.GenericArguments)
generity += GetTypeGenerity(typeArg);
return generity;
}