Good answers here. Clarifying the proposed answer is that you would rather get the value of the enumeration, given the description of the enumeration . I have not tested this, but this may work:
Enum:
public enum e_BootloadSource : byte
{
[EnumMember]
[Display(Name = "UART")]
[Description("UART_BL_RDY4RESET")]
UART = 1,
[EnumMember]
[Display(Name = "SD")]
[Description("SD_BL_RDY4RESET")]
SD = 2,
[EnumMember]
[Display(Name = "USB")]
[Description("USB_BL_RDY4RESET")]
USB = 3,
[EnumMember]
[Display(Name = "Fall Through Mode")]
[Description("FALL_THRGH_BL_RDY4RESET")]
FALL_THROUGH_MODE = 4,
[EnumMember]
[Display(Name = "Cancel Bootload")]
[Description("BL_CANCELED")]
CANCEL_BOOTLOAD = 5,
}
Use the following:
foreach(e_BootloadSource BLSource in Enum.GetValues(typeof(e_BootloadSource)))
{
if (BLSource.GetDescription() == inputPieces[(int)SetBLFlagIndex.BLSource])
{
newMetadata.BootloadSource = BLSource;
}
}
Note. The input elements are a purely string array, and newMetadata.BootloadSource is e_BootloadSource.
source
share