문제

I have:

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

[Foo]
public class Bar1
{
}

[Foo]
public class Bar2
{
}

[Foo]
public class Bar3
{
}

Then I do:

var attrs = CustomAttributeExtensions.GetCustomAttributes(typeof(Bar1).GetTypeInfo().Assembly);

I had expeced that attrs should contain the Foo attribute,, but that is not true. Instead attrs contains 12 other attributes.

Whats wrong??

도움이 되었습니까?

해결책

Maby not plesant,,, but Hans answer workes for me.

If you want to find all of the types that have a this attribute then you have to enumerate the types in the assembly, Assembly.GetTypes(). Tough cookies on winrt. – Hans Passant 20 hours ago

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top