Supose i have:
class MyBase<T1, T2>{}
class MyConcreteBase<T2> : MyBase<ConcreteType1, T2>{}
class MyConcrete1 : MyConcreteBase<ConcreteType2>{}
class MyConcrete2 : MyBase<ConcreteType1, ConcreteType2>{}
How do i get types of T1
and T2
if i have instance of MyConcrete1
or MyConcrete2
or MyConcreteBase
or any other instance of type derived from MyBase<T1, T2>
The way i do it now is i'm "getting up" by inheritance chain using .GetType().BaseType
while BaseType.Name.StartsWith("MyBase")
and then using .GetGenericArguments()
It is working, but i'm not satisfied with it, especially .StartsWith("MyBase")
part.
Anyone have other suggestions?