开发者

find name of all classes with their namespace

开发者 https://www.devze.com 2023-01-14 21:26 出处:网络
how can i find all classes in my assembly which their name space start with MyProject and ends with Attribute

how can i find all classes in my assembly which their name space start with MyProject and ends with Attribute for example:

MyProject开发者_StackOverflow中文版.Model.Attribute or MyProject.Personnel.Jobs.Attribute?


You can easily do this with Linq:

var myClasses = GetType().Assembly.GetTypes()
                   .Where(t => t.Namespace.StartsWith("MyProject") && t.Namespace.EndsWith("Attribute"));


     Assembly assembly = Assembly.GetExecutingAssembly();

     foreach (var type in assembly.GetTypes())
     {
        if (type.Namespace.StartsWith("MyProject") && type.Namespace.EndsWith("Attribute"))
        {
           Console.WriteLine(type.FullName);
        }
     }


This could be achieved using LINQ and reflection.

var desiredTypes =
                myAssembly.GetTypes().Where(
                    item => item.Namespace.StartsWith("MyProject") && item.Namespace.EndsWith("Attribute"));
0

精彩评论

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