I have the following enumeration:
public enum AuthenticationMethod
{
FORMS = 1,
WINDOWSAUTHENTICATION = 2,
SINGLESIGNON = 3
}
T
When I'm confronted with this problem, there are a couple of questions that I try to find the answers to first:
The simplest way to do this is with Enum.GetValue
(and support round-tripping using Enum.Parse
). It's also often worth building a TypeConverter
, as Steve Mitcham suggests, to support UI binding. (It's not necessary to build a TypeConverter
when you're using property sheets, which is one of the nice things about property sheets. Though lord knows they have their own issues.)
In general, if the answers to the above questions suggest that's not going to work, my next step is to create and populate a static Dictionary
, or possibly a Dictionary
. I tend to skip the intermediate decorate-the-code-with-attributes step because what's usually coming down the pike next is the need to change the friendly values after deployment (often, but not always, because of localization).