I’ve the following attribute:
class HandlerAttribute : System.Attribute
{
public string MainName { get; private set; }
public string SubName { get; private set; }
public HandlerAttribute(string pValue, bool pIsMain) {
if (pIsMain) MainName = pValue;
else SubName = pValue;
}
}
And this is the way I use the attribute
[Handler("SomeMainName", true)]
class Class1 {
[Handler("SomeSubName", false)]
void HandleThis() {
Console.WriteLine("Hi");
}
}
What I want to achieve is that I import the MainName value from the parent class attribute into the method defined inside the class.
I hope that someone can help me with this 🙂
Thanks in advance
I would advice to write a helper method for this, basically it isn’t possible by default because you don’t have access to the attribute’s target.
Code
Usage
You can use it with any member and if you write a extension method you can make it even shorter.