0

I have three attributes that I need to apply to a lot of fields in a class. The code looks like this:

[AAttribute, CAttribute, CAttribute]  
private string fieldName;

Is it possible to define another attribute (for example DAttribute) that applies the effect of the other 3 attributes? So I can reduce the boilerplate and convert the code to something like this:

[DAttribute]  
private string fieldName;
PNarimani
  • 614
  • 7
  • 23
  • 1
    Short answer: no. Longer answer: smells like a redesign of your attribute model might be in order. For example, one attribute that has a `[Flags]` enum property might cover all cases. – Jeroen Mostert Jul 23 '19 at 11:23
  • Wow. Be sure to carefully review if the answer posted in the dupe is really what you need, because functionally that's killing a fly with a cannon. It has some merit if you are in no position to change the attribute structure in any way and more mundane solutions like code generation won't help you, but it wouldn't be the first thing I turn to. – Jeroen Mostert Jul 23 '19 at 11:27
  • I cannot change the attributes since they are in compiled dll. But I believe the solution in the dupe is overkill too. I guess I have to live with it. – PNarimani Jul 23 '19 at 11:37

0 Answers0