开发者

find name of all classes with their namespace

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜