Question

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??

Était-ce utile?

La solution

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top