Reflection

  • Thread starter Thread starter Martin Hazell
  • Start date Start date
M

Martin Hazell

I have an abstract class, with some other classes
inheriting from it in my namespace.

What I am would like to know is: is there any way (using
reflection) that I would be able to get a list of what
these possible classes are, that derive from the abstract
class?

Not too hot on reflection at the moment, but trying to
learn as I go.

Thanks for any help in advance

Martin
 
Martin Hazell said:
I have an abstract class, with some other classes
inheriting from it in my namespace.

What I am would like to know is: is there any way (using
reflection) that I would be able to get a list of what
these possible classes are, that derive from the abstract
class?

Not too hot on reflection at the moment, but trying to
learn as I go.

If you know which assemblies the derived classes will be in, you can
get a list of types (Assembly.GetTypes) and then for each type, use
Type.IsAssignableFrom, eg baseType.IsAssignableFrom (typeToTest).
 
Hi Martin,

Actully, if you only have the base class, there are no way to get all the
inherited subclasses.(Because you do not know which class inherited your
base class).
But if you already get a class type or a class instance, you can determine
whether it was inherited from base class.
For example, you can use Type.IsSubclassOf method to get this done.

To learn more information about Reflection, you need refer to the
System.Reflection namespace.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Thanks - think this will help, as I can get a list all of
the possible classes, I just need to iterate through them
all to find out now.

Martin
 
Back
Top