To try make it short, I have created the following enum
public enum Frequency
{
[Description("Monthly")]
Monthly,
[Description("Quarterly")]
Quarterly,
[Description("N/A")]
NA
}
I then have a combo box using the same description strings.
When I select a new selection, specifically the "N/A" one, it fails to read it correctly.
The code that I am using to search for the right enum based on the passed in string is...
/// Returns an enum of the specified type that matches the string value passed in. Note this does ignore case
<param name="value">The string value.</param>
public static TEnum GetEnum<TEnum>(string value)
{
if (string.IsNullOrEmpty(value))
{
// Default not set value name
value = "None";
}
return (TEnum)System.Enum.Parse(typeof(TEnum), value.Replace(" ", string.Empty), true);
}
So when the value = "N/A", I get the following error..
"An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll"
Additional information: Requested value 'N/A' was not found."
I can't seem to understand why this could be happening. There is another, pre-existing combo box where the decription also contains a '/' character and the same error happens. So its not something I have done wrong, it seems, but just the behavior of the enum string checking.
Any insight into why this is causing problems would be incredibly appreciated. :) Thanks!
EDIT: More information..
So this is the code that triggers the enum search..
if (this.FrequencyCombo.SelectedItem != null && !this.FrequencyCombo.SelectedItem.Equals(Utilities.GetDescription(currentLoan.Frequency)))
{
currentLoan.Frequency = Utilities.GetEnum<Frequency>(this.FrequencyCombo.SelectedItem.ToString());
}