Find all class names in a WPF project
In WPF, how do I use reflection to find all classes in a proj开发者_C百科ect? I'm interested in obtaining the ones whos names match a certain regular expression.
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.
精彩评论