Sometime we need to get enumeration items as a list to bind it to some data controls like drop downs.
Here is how we can do that. Suppose we have following enumeration:
PendingVerification = 1,
PendingAdminApproval = 2,
Active = 3,
BlockedByAdmin = 4
We want to bind a dropdown on manage users page with these items. As you know dropdown have two properties for each item, one to handle display value and the other to handle backend value.
Using the current definition of enumeration we can use the name of enumeration item as display property and underlying integer value as backend value but it will not look good as there will be no space between words like PendingVerification. It will be more readable if it is Pending Verification.
So let’s add Description attribute to the enumeration items. Updated enumeration will look like this: