I have this enum:
public enum PPossumResp
{
[EnumName("No Dyspnea")]
NoDyspnea = 1,
[EnumName("Dyspnea On Exertion")]
DyspneaOnExertion = 2,
[EnumName("Mild COPD on CXR")]
MildCOPDonCXR = 2,
[EnumName("Limited Dyspnea")]
LimitedDyspnea = 4,
[EnumName("Moderate COPD")]
ModerateCOPD = 4,
[EnumName("Dyspnea At Rest")]
DyspneaAtRest = 8,
[EnumName("Fibrosis")]
Fibrosis = 8
}
and I am trying to populate a List with all the EnumName attributes.
I have this method that tries to do it:
public EnumPickerViewModel(Parameter param)
{
this.param = param;
List<string> enumNames = new List<string>();
foreach(Enum type in Enum.GetValues(param.Value.GetType()))
{
enumNames.Add(Utils.GetEnumName(type));
}
}
Unfortunately, enumNames is populated with the following: 0: No Dyspnea 1: Dyspnea on Exertion 2: Mild COPD on CXR 3: Limited Dyspnea 4: Limited Dyspnea 5: Dyspnea at Rest 6: Dyspnea at Rest
Since Limited Dyspnea and Moderate COPD have the same value of 4, and Dyspnea at Rest and Fibrosis have the same value of 8, it looks like Enum.GetValues() only gets the first value and takes that string attribute. How can I get all of the enum names despite repeated values?