/// <summary> /// Gets the description of enum value that attached <see cref="System.ComponentModel.DescriptionAttribute" />. /// </summary> /// <param name="enum">The enum.</param> /// <returns>enum string if not assigned.</returns> /// <exception cref="System.ArgumentException">enumValue must be of Enum type;@enum</exception> public static string GetDescription(this Enum @enum) { var desc = @enum.GetCustomAttribute <System.ComponentModel.DescriptionAttribute>(); if (desc == null) { return(@enum.ToString()); } else { return(desc.Description); } }
public static string GetDescription(this Enum value) { var attribute = value.GetCustomAttribute <DescriptionAttribute>(); return(attribute == null?value.ToString() : attribute.Description); }
public static string GetDisplayName(this Enum value) { var attribute = value.GetCustomAttribute <DisplayAttribute>(); return(attribute == null?value.ToString() : attribute.Name); }