To get the type of the immediate parent, you can use the Type.BaseType property. You can iteratively call BaseType until it returns null in order to approach the type inheritance hierarchy.
For instance:
public static IEnumerable<Type> GetInheritanceHierarchy (this Type type) { for (var current = type; current != null; current = current.BaseType) yield return current; }
Note that it is not permissible to use System.Object as the endpoint, because not all types (for example, interface types) inherit from it.
source share