I'm playing around with some classes and interfaces, and have developed a simple method to determine the hierarchy of a class, i.e. to identify the chain of inheritance.
public static void OutputClassHierarchy(Type ty)
{
if (ty.BaseType == null)
{
Console.WriteLine("{0}: Base", ty);
Console.WriteLine("");
return;
}
Console.WriteLine("{0} : {1}", ty, ty.BaseType);
OutputClasshierarchy(ty.BaseType);
}
So, for
OutputClassHierarchy(typeof(System.Exception));
I get the output:
System.Exception : System.Object
System.Object : Base
Which is what I expect.
But, If I attempt the same with an Interface that implements another interface, i.e.
interface IMyInterface : IDisposable
{
void Hello();
}
...
OutputClassHierarchy(typeof(IMyInterface));
I get the output:
MyNameSpace.IMyInterface : Base
So, what is going on here? Is it possible to infer the interface hierarchy as declared above, or is there no such thing when it comes to interfaces?
Also, where is System.Object
in all of this? I thought everything was built upon it.