Reputation: 4671
I have the below enum that I use for one of my filters and suit well to my object model
public enum ColorGroups
{
White = 1,
Brown = 2,
Red = 3,
Black = 4
}
My concern is in the future when a client want to another color to the collection how do I extend the collection. I want the system to be fully dynamic and does not require a technical person to alter the code for such things..
Upvotes: 1
Views: 256
Reputation: 311526
I want the system to be fully dynamic and does not require a technical person to alter the code for such things..
"Fully dynamic" and "use an enum
" are mutually exclusive if you don't want a technical person to have to get involved to make changes. A database or a configuration file is a better choice here.
Upvotes: 1
Reputation: 4971
An enum may not be the right tool for the job in that case. You would be better off using a set of configuration options. These could be in a config file, in the registry or in a database, depending upon what is available to you and whether you want the configuration to be undertaken by a developer or consultant, or by the users of the system.
Upvotes: 1
Reputation: 1062945
If you want the data to be user-editable, it may not be suitable to use an enum. Enums are compile-time units, so will require a developer (or some hacky code generation).
Instead, consider using a database table for this data, pre-populated with your items (and perhaps with a "System" column to control which ones are user-defined vs required by the system). Then changes are just inserts (etc) to the table.
You can, of course, use any other storage mechanism - for example, a delimited string in a config file - but I'm guessing you'll want a database somewhere in the system?
Upvotes: 4