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"));
精彩评论