views:

65

answers:

1

In WPF, how do I use reflection to find all classes in a project? I'm interested in obtaining the ones whos names match a certain regular expression.

+5  A: 

Something along the lines of

 var assemblies = AppDomain.CurrentDomain.GetAssemblies()
   .Where(a => a.GetName().Name.StartsWith("MyCompany"));

var types =         from asm in assemblies
                    from type in asm.GetTypes()
      where Regex.IsMatch(type.FullName,"MyRegexp")
      select type.Name;

You can also load a specific assembly and filter the types you want.

Yann Schwartz
My project uses more than one assembly, I'd like to know how to iterate through all of them. Anyway, thanks for the answer!
luvieere
I edited the answer to look for all assemblies in the current AppDomain
Yann Schwartz