"Jon Skeet" <sk***@pobox.com> wrote in message
news:MP************************@news.microsoft.com ...
Justin Rogers <Ju****@games4dotnet.com> wrote: The .NET QuickStart tutorials have an excellent ClassBrowser application
that encapsulates methods for finding inheritance chains and derived
classes. It is not difficult to find derived classes, just time
consuming, since as Val points out you have to iterate over all types and check their
inheritance chains to see if they derive from the target type.
You don't have to go through their inheritance chains manually - just
use Type.IsAssignableFrom
I'd use Type.IsSubclassOf in this context. Type.IsAssignableFrom would
do the right thing, except for claiming that the class inherits itself ;), but
is so unbelievably badly named it's almost guaranteed to cause confusion.
This simple program demonstrates why i feel Type.IsAssignableFrom is not just
badly named, but incorrectly named:
using System;
class Temp
{
[STAThread]
static void Main(string[] args)
{
int myInt = (short)1;
Console.WriteLine(typeof(int).IsAssignableFrom(typ eof(short)));
}
}
<snip>
/Magnus Lidbom