Here is some test code:
public enum ItemType : byte
{
[EnumMember(Value = "Computers & Electronics")]
ComputersAndElectronics,
[EnumMember(Value = "Music/Movies")]
MusicMovies,
Other
}
public void Test()
{
string testString1 = "Computers & Electronics";
ItemType itTest1 = ??? // should be assigned "ItemType.ComputersAndElectronics"
string testString2 = "Other";
ItemType itTest2 = ??? // should be assigned "ItemType.Other"
}
The values I will be getting from an outside source are the strings in the EnumMember
attributes (except for the last enum value, which can be used directly as a parameter name)
I'm not sure how to parse the expanded strings into the Enum type. Enum.Parse
only seems to parse a string containing the actual C# parameter name for the enum value (e.g. `"ComputersAndElectronics" will properly parse, but "Computers & Electronics" will not.)
The "Other" case is important since that item does not have an EnumMember attribute.