Link to home
Start Free TrialLog in
Avatar of axnst2
axnst2Flag for United States of America

asked on

Get a list of all of a class's base types recursively

HI Experts,

The title says it all:  How do I get a list of all of a class's base types recursively.

So if I have this:

interface A
    { }
    class B : A
    { }
    class C : B
    { }

I would like a list containing A, B, and C.

I could do it using reflection and recursively get object.BaseType.Name over and over again, but is there anything else built into the framework?

Thanks!
Avatar of kaufmed
kaufmed
Flag of United States of America image

An interface will never be a base type. You implement an interface; you inherit a base class.

To get the base classes, yes, you can use reflection. It doesn't need to be recursive, though.
Avatar of axnst2

ASKER

Ok, I'm not worried about interfaces, but how would reflection give me the names of all of a Type's base types without putting BaseType.Name into a recursive function of somekind.  

Otherwise, i would get a list of ALL Types in the assmbly even if they are not related to each other what so ever...
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of axnst2

ASKER

As I stated in my original post, I know I have a way of obtaining the info by using a recursive function, I was just hoping I guess that there was a better way of doing it.
Avatar of axnst2

ASKER

Thanks!