Skip to main content

Posts

Showing posts with the label ENUM

CSharp - ENUM utility methods

During development sometimes we come across the situation to get the enum specification, means list of available Name, Value or attribute description (if available).   Here are the sample methods to get these enum details: (C# code example)  /// /// Get all the values Description of this Enum /// /// enum type /// public static List GetDescrptionList () where TEnum : struct { if (!typeof(TEnum).IsEnum) { throw new ArgumentException("TEnum must be an enumerated type"); } var enumType = typeof(TEnum); var enumDescriptionList = new List (); foreach (var value in Enum.GetValues(enumType)) { var enumDescription = GetDescription((Enum)value); enumDescriptionList.Add(enumDescription); } return enumDescriptionList; } /// /// Get the description field of this Enum ...