
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
Finding the Subclasses of a Type
|
769
Derived Type: CSharpRecipes.ReflectionUtils+BaseOverrides
Base Type List: Object<-BaseOverrides
Derived Type: CSharpRecipes.ReflectionUtils+DerivedOverrides
Base Type List: Object<-BaseOverrides <-DerivedOverrides
This output shows that when looking at the Reflection class in the CSharpRecipes
namespace, its base-type list (or inheritance hierarchy) starts with Object (like all
types in .NET). The nested class
BaseOverrides also shows a base-type list starting
with
Object. The nested class DerivedOverrides shows a more interesting base-type
list, where
DerivedOverrides derives from BaseOverrides, which derives from Object.
Discussion
Unfortunately, no property of the Type class exists to obtain the inheritance hierar-
chy of a type. The
DisplayInheritanceChain methods in this recipe allow you to
obtain the inheritance hierarchy of a type. All that is required is the path to an assem-
bly and the name of the type with the inheritance hierarchy that is to be obtained.
The
DisplayInheritanceChain method requires only an assembly path since it dis-
plays the inheritance hierarchy for all types within that assembly.
The core code of this recipe exists in the
GetBaseTypeList method. This is a recursive
method that walks each inherited type until it finds the