[英]All built-in .Net attributes
我使用AppDomain.CurrentDomain.GetAssemblies()
列出了所有程序集,但是如何使用C#列出.NET 2.0中的所有内置属性?
Note that AppDomain.GetAssemblies()
will only list the loaded assemblies... but then it's easy: 请注意, AppDomain.GetAssemblies()
将仅列出已加载的程序集......但这很容易:
var attributes = from assembly in assemblies
from type in assembly.GetTypes()
where typeof(Attribute).IsAssignableFrom(type)
select type;
.NET 2.0 (non-LINQ) version: .NET 2.0(非LINQ)版本:
List<Type> attributes = new List<Type>();
foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
{
foreach (Type type in assembly.GetTypes())
{
if (typeof(Attribute).IsAssignableFrom(type))
{
attributes.Add(type);
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.