hi, there any way to define enum in c# like below?
public enum MyEnum : string
{
EnGb = "en-gb",
FaIr = "fa-ir",
...
}
ok, according to erick approach and link, i'm using this to check valid value from provided description:
public static bool IsValidDescription(string description)
{
var enumType = typeof(Culture);
foreach (Enum val in Enum.GetValues(enumType))
{
FieldInfo fi = enumType.GetField(val.ToString());
AmbientValueAttribute[] attributes = (AmbientValueAttribute[])fi.GetCustomAttributes(typeof(AmbientValueAttribute), false);
AmbientValueAttribute attr = attributes[0];
if (attr.Value.ToString() == description)
return true;
}
return false;
}
any improvement?