Get Inheriting types

  • Thread starter Thread starter Jeremy
  • Start date Start date
J

Jeremy

Hi Guys,

How do I get all the inheriting types of a specific type
I guess I can get this using reflection...

Could someone pls point me to an example or resource

thanks
 
How do I get all the inheriting types of a specific type
I guess I can get this using reflection...

AFAIK you can only get parent classes, otherwise every class that you wrote
would have to contain provision for listing every single class that ever
derived from it. How could you determine that ? Only possibly within one
assembly.

Joanna
 
I am only interested in a single assembly, I guess all of
that information is in there..

and will this be possible for only a single assembly

Isnt this how the treeviews in the object browser ,
reflector are being constructed ..?

please correct me if i am wrong
 
You can do that by loading the assembly, iterating through all the
types and using IsSubClassOf to find if it inherits from a specific
type. Something like

Assembly s = Assembly.Load("...");
foreach(Type t in s.GetTypes())
{
if (t.IsSubClassOf(baseType))
{
//do whatever you want to
}
}
 
Back
Top