I define multiple attributes on a class:
[CustomAttribute("a", state = 0)]
[CustomAttribute("b", state = 0)]
...
[CustomAttribute("z", state = 0)]
public class MyClass { ... }
The values ("a"
, "b"
, on through to "z"
) are also used elsewhere in the program, so right now, I have a duplicate array of names.
public static readonly string[] listOfNames = new [] { "a", "b", ..., "z" };
I can recover the names from the attributes using reflection to build listOfNames
, but is there a way to do the reverse and define the attributes from listOfNames
? I suspect not, but then is there a clearer way to at least avoid repeating the CustomAttribute
bit?