3

Possible Duplicate:
Get Enum from Description attribute

Hi All, I have and Enum defined like this.

public enum SomeType {
        [Description("One Value")]
        One,
        [Description("Two Value")]
        Two,
        [Description("Three Value")]
        Three       
    }

but when I try to parse a string like this

SomeType  test =  (SomeType )Enum.Parse(typeof(SomeType ), "Three Value");

I get excetion "Requested value 'Three Value' was not found". Isn't this supposed to work ?

Thanks

Community
  • 1
  • 1
dcmovva
  • 155
  • 1
  • 3
  • 10

2 Answers2

2

No, it's not. You can find the Enum by the enum Name ("One", "Two", "Three"), but not by Description (at least not that way). Maybe via Reflection...

You might wanna take a look at this: How to get C# Enum description from value?

Update

Take a look at @KIvanov's comment and look here: Get Enum from Description attribute

Community
  • 1
  • 1
Adriano Carneiro
  • 57,693
  • 12
  • 90
  • 123
1

As far as I know

SomeType  test =  (SomeType )Enum.Parse(typeof(SomeType ), "Three");

would do what you want

m.edmondson
  • 30,382
  • 27
  • 123
  • 206