Accessing EnumDisplayValue programmatically


Author
Message
Leonard P.
Leonard P.
StrataFrame Novice (83 reputation)StrataFrame Novice (83 reputation)StrataFrame Novice (83 reputation)StrataFrame Novice (83 reputation)StrataFrame Novice (83 reputation)StrataFrame Novice (83 reputation)StrataFrame Novice (83 reputation)StrataFrame Novice (83 reputation)StrataFrame Novice (83 reputation)
Group: Awaiting Activation
Posts: 65, Visits: 306
Hello,

Lets seay I have this enum type:

 public enum MyEnum
    {
        [EnumDisplayValue("This is Value 1")]
        value1 = 1,
        [EnumDisplayValue("This is Value 2")]
        value2 = 2
    }

Now consider this code:

   

MyEnum myEnum = MyEnum.value2;
MessageBox.Show(myEnum.ToString());

The messagebox displays "value2", but I would like to see EnumDisplayValue "This is Value 2".

Is there an easy way to get the value of that attribute? I have a feeling I need to use reflections to get it.

Thank you for your help.

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...





Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search