private Type SystemTypeFrom(IType entity)
{
var external = entity as ExternalType;
if (null != external)
return external.ActualType;
if (entity.IsArray)
{
IArrayType arrayType = (IArrayType)entity;
Type systemType = GetSystemType(arrayType.ElementType);
int rank = arrayType.Rank;
if (rank == 1) return systemType.MakeArrayType();
return systemType.MakeArrayType(rank);
}
if (entity.ConstructedInfo != null)
{
// Type is a constructed generic type - create it using its definition's system type
Type[] arguments = Array.ConvertAll<IType, Type>(entity.ConstructedInfo.GenericArguments, GetSystemType);
return GetSystemType(entity.ConstructedInfo.GenericDefinition).MakeGenericType(arguments);
}
if (entity.IsNull())
return Types.Object;
if (entity is InternalGenericParameter)
return (Type)GetBuilder(((InternalGenericParameter)entity).Node);
if (entity is AbstractInternalType)
{
TypeDefinition typedef = ((AbstractInternalType) entity).TypeDefinition;
var type = (Type)GetBuilder(typedef);
if (null != entity.GenericInfo && !type.IsGenericType) //hu-oh, early-bound
DefineGenericParameters(typedef);
if (entity.IsPointer && null != type)
return type.MakePointerType();
return type;
}
return null;
}