2

Not even sure if possible because can't find anything about that, i can find how to GET the current description written before program is executed but can't find a way to change (set/edit) the description of an enum when the program is already started, so if i have (just an example):

public enum MyColors {
    [Description("This is green, like a cactus")]
    Green,
    [Description("This is red, like blood")]
    Red,
    [Description("This is blue, you know like water")]
    Blue,
    [Description("This is black, like the eyes of an alien")]
    Black
}

How can i change the description during the program execution (while app is already started) or tell me "not possible" if it's not possible, thanks for your time.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Goty Metal
  • 196
  • 14
  • You could add a dictionary (- observable if you need binding -) that has the enum values as key and the description as value, then use that instead. If it's for localization you could just associate a key string using an attribute and then look that up in you current localization context. – H.B. Jun 28 '16 at 07:55
  • That's exatly what i'm was doing ;) – Goty Metal Jun 28 '16 at 07:56

2 Answers2

3

You cannot change the value of the Description attribute, because attribute values are static and are baked into the compiled assembly.

Tomáš Hübelbauer
  • 9,179
  • 14
  • 63
  • 125
0

Your description is defined in an attribute. The parameter (string) is compiled into the Intermediate Language IL hence they form part of your assembly. As a consequence you cannot change the description during run-time.

You will need to change the way you link enum values and descriptions if you require to change them during run-time. One way is to change to resource files.

Quality Catalyst
  • 6,531
  • 8
  • 38
  • 62