Enum wrapper for more conviently accessing the Display DataAnnotation Attribute on an Enum
- Use by copy-pasting EnumAnnotation.cs into your project, and modify as you see fit
- Or reference the assembly using Nuget
Install-Package EnumAnnotation
- Use the in .net 4 added
System.ComponentModel.DataAnnotations.DisplayAnnotation
to add friendly names to your Enum - Generate Lists with enum names and values to bind in your UI, using
EnumAnnotation.GetDisplays<SomeStatus>();
Filter these Lists by supplying the enum values explicitly
EnumAnnotation.GetDisplays(SomeStatus.Fine, SomeStatus.Ok);
or using a lambda predicate function
EnumAnnotation.GetDisplays<SomeStatus>(a => a.Name != "Fine");
- Add multiple names to your Enums using the DisplayAnnotations
Name
,ShortName
,Desciption
andGroupName
properties - Supports the
DisplayAnnotation.ResourceType
to add localization to theName
,ShortName
,Desciption
andGroupName
properties using standard resx files. See example and unit tests - Extension method to easy access a DisplayAttribute on a single enum value, which looks like
SomeStatus.Fine.GetDisplay();
, - or access the Name value directly, using
SomeStatus.Fine.GetName();
- Reorder your Enum using the
DisplayAnnotion.Order
property, without changing the Enums Underying value - Portable libary that supports .Net 4.03, Silverlight 5 and Windows 8 and up. Portable libraries are supported in Nuget 2.1 and up