There is a code earlier (it was published a little earlier by @ iluxa1810)

[Flags] enum Rights { Default = 0x000001, Vip = 0x000002 | Default, Admins = 0x000004 | Vip, FullAdmins = 0x000008 | Admins } 

I need just the same solution, but with loading enum from json.

Is there a ready-made example or project? I just can't figure out how to do

  • Use a regular class and in runtime just create instances of it, for convenience you can create operators to convert to / from int - Andrey NOP

1 answer 1

Enum are constants, they are defined at the compilation stage. ( There are, of course, perverted ways, but this is hardly what you would like to do. )

In runtime, you can use a Dictionary<string, int> for the same purpose.

  • In principle, it would also suit me to create a separate assembly from that example. low - fehar
  • something like myEnum.DefineLiteral("High", 1 | lowValue); . But creating an assembly for a single enum is a perversion, think again!) - free_ze
  • doesn't work. Better build than a lot of configs - fehar
  • @fehar, than just the dictionary did not suit you? It's hard for me to imagine a case when I need to generate an enum. - free_ze
  • just turned to enum and if more is needed - perform the action. And with the dictionary parse more - fehar