我已使用 AppDomain.CurrentDomain.GetAssemblies()
列出所有程序集,但如何使用 C# 列出 .NET 2.0 中的所有内置属性?
最佳答案
请注意,AppDomain.GetAssemblies()
只会列出已加载 的程序集...但这很容易:
var attributes = from assembly in assemblies
from type in assembly.GetTypes()
where typeof(Attribute).IsAssignableFrom(type)
select type;
.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);
}
}
}
关于c# - 所有内置 .Net 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3888260/