I want to be able to find all parent types (base classes and interfaces) for a specific type.
EG if i have
class A : B, C { }
class B : D { }
interface C : E { }
class D { }
interface E { }
i want to see that A is B C D and E and Object
Whats the best way to do this? is there a reflection method to do this or do i need to make myself something.
====EDIT====
So something like this?
public static IEnumerable<Type> ParentTypes(this Type type)
{
foreach (Type i in type.GetInterfaces())
{
yield return i;
foreach (Type t in i.ParentTypes())
{
yield return t;
}
}
if (type.BaseType != null)
{
yield return type.BaseType;
foreach (Type b in type.BaseType.ParentTypes())
{
yield return b;
}
}
}
I was kinda hoping i didn't have to do it myself but oh well.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…