1

Possible Duplicate:
How to determine the attached type from within a custom attribute?

I have this custom class attribute:

[AttributeUsage(AttributeTargets.Class)]
public class ConfigurableClass : Attribute
{

    public Type Control { get; private set; }
    public bool IsSingleton { get; private set; }
    public string Name { get; private set; }

    public ConfigurableClass(bool isSingleton) : this(null, isSingleton)
    {
    }

    public ConfigurableClass(Type control, bool isSingleton)
    {
        Control = control;
        this.IsSingleton = isSingleton;
        this.Name = ""; //set name to typename of the attached class here?
    }

    public ConfigurableClass(Type control, bool isSingleton, string name) : this(control, isSingleton)
    {
        this.Name = name;
    }

}

Notice the line with the comment in it. Is it possible to get the type of the class that this class-attribute is attached to, or is it not?

Community
  • 1
  • 1
Mathias Lykkegaard Lorenzen
  • 15,031
  • 23
  • 100
  • 187

1 Answers1

3

That's not possible, I'm afraid, but the code that reads the attribute from the class will know which class it is reading from. So whatever you need to do with that class name should be done there.

pdr
  • 6,372
  • 1
  • 29
  • 38