开发者

Find all class names in a WPF project

开发者 https://www.devze.com 2022-12-09 12:38 出处:网络
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

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消