In C# I have
class Gen1<T1, T2> {}
class Gen2<T2>: Gen1<MyObject, T2> {}
class Ins: Gen2<MyInterface> {}
var ins = new Ins();
Type insType = ins.GetType();
How can I get MyObject
and MyInterface
from insType (with correct order?)
I tried:
List<Type> types = new List<Type>();
do
{
types.AddRange(checkType.GetGenericArguments());
if(checkType.IsGenericType)
{
Type genType = checkType.GetGenericTypeDefinition();
types.AddRange(genType.GetGenericArguments());
}
checkType = checkType.BaseType;
} while (checkType != null);
This gives MyInterface
and T2
. It did find the Gen2<T2>
type, but I have no idea how to get that MyObject
when Gen2 inherent from Gen1, and how to make the order correct too.
Thanks!