By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,155 Members | 1,398 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,155 IT Pros & Developers. It's quick & easy.

Find inherited classes / walk inheritance tree

P: n/a
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

May 21 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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/lib....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

May 21 '06 #2

P: n/a
Thank you
this helps.
- is there a way to "find all Assemblies involved in
"The_Current_Application"

Peter

May 21 '06 #3

P: n/a
take a look at Assembly.GetReferencedAssemblies Method

http://msdn2.microsoft.com/en-us/lib...ssemblies.aspx

thus way you can start from single assembly and get all dependency ones

hope ths helps
Galin Iliev[MCSD.NET]
www.galcho.com

May 22 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.