示例#1
0
        /// <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);
            }
        }
示例#2
0
        public static string GetDescription(this Enum value)
        {
            var attribute = value.GetCustomAttribute <DescriptionAttribute>();

            return(attribute == null?value.ToString() : attribute.Description);
        }
示例#3
0
        public static string GetDisplayName(this Enum value)
        {
            var attribute = value.GetCustomAttribute <DisplayAttribute>();

            return(attribute == null?value.ToString() : attribute.Name);
        }