簡體   English   中英

所有內置的.Net屬性

[英]All built-in .Net attributes

我使用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);
        }
    }                   
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM