In this episode of Programming with Palermo, Jeffrey discusses the options and limitations of working with enumerated lists in .NET.
Code sample: https://github.com/jeffreypalermo/sample-enumerated-classes
Populating drop-down lists and multi-select lists has always been a challenge in interactive software. Some lists can be hard-coded because they do not change (male/female, yes/no, day/night). Other lists must be more dynamic, such as States the company services. Further, some known options in lists are required for business logic, while others can be loaded from a database. Here are the general options you must choose from the characteristics of them.
Java enums are very different from C# enums. In some way, Java has more built-in support in the language for richer enums, whereas C# leaves more up to the programmer. Regardless, any need can be satisfied with the right design pattern. The programmer must understand the tensions of the software in order to know the appropriate architectural element to introduce.
C# enums (enumerations) are compiled in code and have a value of an Int32 but can be made smaller by using the smaller integer types (short, etc). They have the name available as well as the integer value. Any change requires the software to be redeployed.
With some custom reflection, one can add any number of attributes onto an enum value. This can allow any number of additional pieces of information to be attached. But new values cannot be dynamically loaded from a database or changes without redeploying the software.
Enumerated classes is a design pattern that uses regular C# classes while making the usage syntax appear like a C# enum. No enum is actually used, but the intellisense experience and the syntax is nearly identical. This approach allows for an arbitrary number of additional properties on an enumerated value while also allowing properties to be updated at runtime as well as additional values in the enumerated listing to be added from any type of database.
Several very feasible options exist for managing drop-down lists and multi-select lists in applications. Each option comes with different capabilities and limitations before a change would require a redeployment of the software.