Reputation: 170
I have an attribute which is dependent on another attribute i.e. it would have no effect unless the other attribute is present. Can I somehow have that whenever that attribute is added to a class, the other attribute gets added too?
For example, there is a Decorator attribute
public class Decorator : Attribute {
public void draw(){}
}
public class Field : Attribute {
public void FunctionThatIsCallingAllDecorators(){
foreach(var attribute in GetAllDrawers()){
attribute.draw();
}
}
...
}
Here decorator attribute is only useful if the class also has a field attribute, so what I want is that any class that is given a decorator attribute also gets a field attribute.
Upvotes: 1
Views: 881
Reputation: 79
Please create constructor in Decorator class. Create one variable of 'Field' and always instantiate in constructor of Decorator.
You can expose this 'Field' variable using property.
Upvotes: 1