Windows runtime 如何从Winrt中的程序集中获取自定义的Attibutes

Windows runtime 如何从Winrt中的程序集中获取自定义的Attibutes,windows-runtime,system.reflection,Windows Runtime,System.reflection,我有: 那么我会: [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] public class FooAttribute : Attribute { } [Foo] public class Bar1 { } [Foo] public class Bar2 { } [Foo] public class Bar3 { } 我曾经尝试过attrs应该包含Foo属性,但事实并非如此。相反,attrs包含12个其他属性

我有:

那么我会:

[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
public class FooAttribute : Attribute
{
}

[Foo]
public class Bar1
{
}

[Foo]
public class Bar2
{
}

[Foo]
public class Bar3
{
}
我曾经尝试过attrs应该包含Foo属性,但事实并非如此。相反,attrs包含12个其他属性


有什么问题吗?

可能不是普莱森特,,,但汉斯的回答对我有用

如果要查找具有this属性的所有类型,则必须枚举程序集assembly.GetTypes()中的类型。温特的硬饼干汉斯·帕桑20小时前


您正在检索[assembly]属性,而不是Bar1类的属性。当然,有很多,当然不是[Foo]。删除
.Assembly
。如果删除它,则仅从Bar1获取属性。Bar2和Bar3呢?如果要查找具有this属性的所有类型,则必须枚举程序集中的类型assembly.GetTypes()。温特的硬饼干。
var attrs = CustomAttributeExtensions.GetCustomAttributes(typeof(Bar1).GetTypeInfo().Assembly);