我曾经用过AppDomain.CurrentDomain.GetAssemblies()列出所有程序集,但是如何使用C#列出.NET 2.0中的所有内置属性?
Jon*_*eet 15
请注意,这AppDomain.GetAssemblies()将只列出已加载的程序集......但是这很容易:
var attributes = from assembly in assemblies
from type in assembly.GetTypes()
where typeof(Attribute).IsAssignableFrom(type)
select type;
Run Code Online (Sandbox Code Playgroud)
.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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
852 次 |
| 最近记录: |