Can an attribute's target be derived from an instance of the attribute?

Posted by Hounshell on Stack Overflow See other posts from Stack Overflow or by Hounshell
Published on 2009-11-16T06:03:24Z Indexed on 2010/05/27 7:41 UTC
Read the original article Hit count: 235

Filed under:
|

Example:

[AttributeUsage(AttributeTargets.Class)]
public class MyAttribute : Attribute
{
  public MyAttribute()
  {
    Console.WriteLine("I was defined on the {0} class", ????);
  }
}

[MyAttribute]
public class MyClass
{
}

Can I fill in the "????" to answer this question? Do I have to iterate over every type in the list of known assemblies to do it? Or is there a shorter way?

© Stack Overflow or respective owner

Related posts about c#

Related posts about attributes