Re: Finding subclasses
From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 11/23/04
- Next message: Sam Martin: "Im only try to get a string..."
- Previous message: Jon Skeet [C# MVP]: "Re: How good an encryption algorithm is this?"
- In reply to: MR: "Finding subclasses"
- Next in thread: Tim Jarvis: "Re: Finding subclasses"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 23 Nov 2004 17:50:45 -0000
MR <MR@discussions.microsoft.com> wrote:
> I'm hoping that someone here will be able to direct me to some litrature on
> how to get a list of a classes subclasses. I.e. need the inherited class to
> know about subclasses that are inherited form it.
>
> I guess that I'll have to use reflection but I can't find any examples on
> MSDN.
You can only look through assemblies to find all subclasses - if you
don't know all the assemblies that might contain subclasses, you can't
find them.
With that restriction, you can use Assembly.GetTypes, and then go
through each type and use Type.IsAssignableFrom to find out if the type
is derived (directly or indirectly) from your base type.
-- Jon Skeet - <skeet@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
- Next message: Sam Martin: "Im only try to get a string..."
- Previous message: Jon Skeet [C# MVP]: "Re: How good an encryption algorithm is this?"
- In reply to: MR: "Finding subclasses"
- Next in thread: Tim Jarvis: "Re: Finding subclasses"
- Messages sorted by: [ date ] [ thread ]