Find inherited classes / walk inheritance tree

P

Peter

Hi,

I have a Class-Tree based on "Command-Pattern"

eg.
public class Calculator
{ ....
}

public abstract class command
{ ..
public abstract void Execute()
{
}
}

public class commandAlpha : command
{ ...
public commandAlpha(Calculator calulator, float alpha)
{
}
}

public class commandGamma : command
{ ...
public commandAlpha(Calculator calulator, float gamma)
{
}
}


public class commandGamma2 : command
{ ...
public commandAlpha(Calculator calulator, float gamma, deviation
float)
{
}
}
.....


Now i will add a Userinterface to test the calculator.
A Combobox should show all Commands, but i will not "hardcode" them to
the combobox. My Ideea is to find all "SubClasses of command" and add
the Type to the Combobox .
1) How can I find all Subclasses of a Class/Type ?
2) How can I find all Subclasses of a Class/Type if there are different
Namspaces/Assemblies ?


Thank you
Peter
 
G

Galcho[MCSD.NET]

you should do the following:
1. determine which assemblies could contain SubClasses of command. all
in specified folder, all on computer... etc.. once you have this you
iterate through them
2. for each assembly iterate through all types by using Reflection
http://msdn2.microsoft.com/en-US/library/system.reflection.assembly.gettypes.aspx

3. for each type use Type.BaseType Property (probably recursive) to
check if one of them is abstract Command class.

I hope this helps
Galin Iliev[MCSD.NET]
www.galcho.com
 
P

Peter

Thank you
this helps.


- is there a way to "find all Assemblies involved in
"The_Current_Application"

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top