Can an attribute's target be derived from an instance of the attribute?
- by Hounshell
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?