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!
axnst2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
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.
0
axnst2Author Commented:
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...
0
käµfm³d 👽Commented:
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.
To my knowledge, that is the only way. You can hold out for more responses, though.

i would get a list of ALL Types in the assmbly even if they are not related to each other what so ever
I don't see how. Calling BaseType would only give you the base type of the type you are calling it against. A class can only inherit from one class. Of course, the class it inherits from can inherit from another class, and that class can inherit a class, etc., etc. But this is what your (recursive) logic would account for.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
axnst2Author Commented:
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.
0
axnst2Author Commented:
Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.