c# - 所有内置 .Net 属性

标签 c# linq

我已使用 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/

相关文章:

c# - C#中的隐式类型转换

c# - LINQ 从两个具有相同长度的集合中选择

asp.net - 使用 Linq 绑定(bind) Gridview 数据源 (asp.net)

C# 将标志枚举类型变量中的设置标志转换为整数数组

c# - 如何使用分页渲染对象树?

c# - 如何从 ARGB 计算窗口颜色

c# - 在大型 .NET 项目中实现多语言/全局化的最佳方式

c# - 具有复合索引的 Nhibernate Map 映射

c# - Monodevelop:从 C#/Visual Studio 移植:双击消失

c# - realm.xamarin 抛出错误 : The method 'Contains' is not supported. 与 'Any' 相同