[英]Is there a built-in .NET method for getting all of the properties and values for an object?
[英]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.