質問

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