Вопрос

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