How to find the inheritance hierarchy of an interface for a type?

My goal is to find out if the class implements the interface directly. In the example below, class B implements IB, and IB implements IA.

How to learn inheritance hierarchy? When we look at a type in Object Explorer, it shows a detailed hierarchy. How can I achieve a similar result?

interface IA { string Member1 { get;set; } } interface IB : IA { string Member2 { get; set; } } class B : IB { public string Member1 { get; set; } public string Member2 { get; set; } } 

Reflector screen shot

alt text http://img571.imageshack.us/img571/7485/49211426.png

The screenshot taken from the reflector also shows the hierarchy of interfaces.

How to find out the hierarchy of an interface for a type.

+4
source share
1 answer

Reflection and the .NET core are built to quickly use interfaces. Thus, Type.GetInterfaces returns all the interfaces to which the type can respond, "smoothing" the hierarchy of the interface in this process.

If you want to guess the pedigree of these interfaces, you will also need to call GetInterfaces on each interface. There is no shortcut because the interface hierarchy is not a big deal for the CLR runtime.

+3
source

All Articles