1

Lets say you have this enum:

Public Enum ApplicationStatus
    <Foo("Active")> Active = 1
    <Foo("Inactive")> Inactive = 2
    <Foo("Retired")> Retired = 3
    <Foo("In Development")> InDevelopment = 4
End Enum

What attribute should I use in place of Foo for plain-text descriptions of the Enum?

Jonathan Allen
  • 68,373
  • 70
  • 259
  • 447

3 Answers3

3

I use Description()

[Description("The image associated with the control"),Category("Appearance")] 
 public Image MyImage {
    get {
       // Insert code here.
       return image1;
    }
    set {
       // Insert code here.
    }
 }
hunter
  • 62,308
  • 19
  • 113
  • 113
1

In addition to hunter's answer, you might want to check out this extension method to retrieve the description easily

Community
  • 1
  • 1
Thomas Levesque
  • 286,951
  • 70
  • 623
  • 758
1

I've used Description for mine, but only in the cases when the enumeration itself needs to display very differently, otherwise it just displays the String of the Enum Value.

I've also use a method for some where it checks the case of each character in the Enum item and if it's an uppercase character after the 1st, it adds a space before the character.

Public Enum ApplicationStatus
    Active = 1
    Inactive = 2
    Retired = 3
    InDevelopment = 4
    <Description("Radical Display Name")> Radical = 5 
End Enum
Paul Farry
  • 4,730
  • 2
  • 35
  • 61
  • 1
    I do the same thing for datagrid columns, though I look for a capital followed by a lower case. That way "IOMode" becomes "IO Mode" instead of "I O Mode". – Jonathan Allen Jul 27 '10 at 02:40