gpt4 book ai didi

c# - 所有内置 .Net 属性

转载 作者:太空狗 更新时间:2023-10-29 22:13:00 28 4
gpt4 key购买 nike

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

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com