If you are interested in all the base types plus interfaces you can use:
static Type[] BaseTypesAndInterfaces(Type type)
{
var lst = new List<Type>(type.GetInterfaces());
while (type.BaseType != null)
{
lst.Add(type.BaseType);
type = type.BaseType;
}
return lst.ToArray();
}
Use it like:
var x = BaseTypesAndInterfaces(typeof(List<MyClass>));
It's even possible to make it generic-based
static Type[] BaseTypesAndInterfaces<T>()
{
Type type = typeof(T);
var lst = new List<Type>(type.GetInterfaces());
while (type.BaseType != null)
{
lst.Add(type.BaseType);
type = type.BaseType;
}
return lst.ToArray();
}
and
var x = BaseTypesAndInterfaces<MyClass>();
but it's probably less interesting (because normally you "discover" MyClass
at runtime, so you can't easily use generic methods with it)