Getting all types from an assembly derived from a base class

Posted by CaptnCraig on Stack Overflow See other posts from Stack Overflow or by CaptnCraig
Published on 2010-03-19T21:29:09Z Indexed on 2010/03/19 21:31 UTC
Read the original article Hit count: 221

Filed under:
|

I am trying to examine the contents of an assembly and find all classes in it that are directly or indirectly derived from Windows.Forms.UserControl.

I am doing this:

Assembly dll = Assembly.LoadFrom(filename);
var types = dll.GetTypes().Where(x => x.BaseType == typeof(UserControl));

But it is giving an empty list because none of the classes directly extend UserControl. I don't know enough about reflection to do it quickly, and I'd rather not write a recursive function if I don't have to.

© Stack Overflow or respective owner

Related posts about c#

Related posts about reflection