Gunnar Peipman's ASP.NET blog

ASP.NET, C#, SharePoint, SQL Server and general software development topics.

Sponsors

News

 
 
 
 
 
DZone MVB

Links

Social

EnumHelper class

Some time ago I wrote blog posting Extension method for enumerators where I showed how to use extension methods to make using of enumerators more convenient. Today I found very interesting posting from Grant Barrington blog where he describes the class called EnumHelper.

As enumerator values are often used on web forms as dropdown lists then we need a way to show nice options to users. Something like BrightPink or MyHomeAddress may confuse them. Grant offers us a nice solution – we can use description attributes to bind user readable values to enumerator members.

Take a look at the following code sample I took from Grant’s blog. It is the best illustration about his work.


using System.ComponentModel; namespace Ellington.EnumHelperExamples { public enum UserColours { [Description("Burnt Orange")] BurntOrange = 1, [Description("Bright Pink")] BrightPink = 2, [Description("Dark Green")] DarkGreen = 3, [Description("Sky Blue")] SkyBlue = 4 } }

It seems cool to me. Thanks Grant!

Comments

Jas said:

Ummm, I'm pretty sure I've seen this implemented before from Mike in March 2008. See www.moggoly.me.uk/.../Enum-description-values.aspx

# January 20, 2009 8:56 AM

Sean said:

# January 20, 2009 2:55 PM

Dew Drop - January 21, 2009 | Alvin Ashcraft's Morning Dew said:

Pingback from  Dew Drop - January 21, 2009 | Alvin Ashcraft's Morning Dew

# January 21, 2009 12:16 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)