TypeSpec[] CreateGenericArguments(int first, MetaType[] tparams, DynamicTypeReader dtype)
{
++dtype.Position;
var tspec = new TypeSpec [tparams.Length - first];
for (int pos = first; pos < tparams.Length; ++pos) {
var type = tparams[pos];
int index = pos - first;
TypeSpec spec;
if (type.HasElementType) {
var element = type.GetElementType ();
++dtype.Position;
spec = ImportType (element, dtype);
if (!type.IsArray) {
throw new NotImplementedException ("Unknown element type " + type.ToString ());
}
spec = ArrayContainer.MakeType (module, spec, type.GetArrayRank ());
} else {
spec = CreateType (type, dtype, true);
//
// We treat nested generic types as inflated internally where
// reflection uses type definition
//
// class A<T> {
// IFoo<A<T>> foo; // A<T> is definition in this case
// }
//
// TODO: Is full logic from CreateType needed here as well?
//
if (!IsMissingType (type) && type.IsGenericTypeDefinition) {
var targs = CreateGenericArguments (0, type.GetGenericArguments (), dtype);
spec = spec.MakeGenericType (module, targs);
}
}
++dtype.Position;
tspec[index] = spec;
}
return tspec;
}