Let's say I have:
class MyBase<T1, T2>{}
class MyConcreteBase<T2> : MyBase<ConcreteType1, T2>{}
class MyConcrete1 : MyConcreteBase<ConcreteType2>{}
class MyConcrete2 : MyBase<ConcreteType1, ConcreteType2>{}
How to get types T1and T2if I have an instance of MyConcrete1or MyConcrete2or MyConcreteBaseor any other type instance derived fromMyBase<T1, T2>
Now, when I do this, I get up on the inheritance chain using .GetType().BaseTypewhile BaseType.Name.StartsWith("MyBase"), and then using.GetGenericArguments()
It works, but I am not satisfied with this, especially the .StartsWith("MyBase")part.
Anyone have any other suggestions?
source
share