Jordan
Jordan

Reputation: 9911

Can one get the type that a specific attribute is decorating

Say I have a situation like so:

[MyAttribute]
public class MyClass
{

}

[AttributeUssage(AttributeTargets.Class)]
public class MyAttribute
{
    public MyAttribute(String a_strName)
    {

    }
}

Is there anyway that within constructor of MyAttribute I can know that the attribute is attached to MyClass?

Upvotes: 1

Views: 37

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1503839

No, I'm afraid not - attributes don't "know" what they're applied to.

Upvotes: 1

Related Questions