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
2009-10-28 15:17:14
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
2009-10-28 15:21:13
I edited the answer to look for all assemblies in the current AppDomain
Yann Schwartz
2009-10-28 15:30:23