Exemple #1
0
        /// <summary>
        ///     获取枚举类型的描述信息
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns>System.String.</returns>
        public static string GetDescription(this Enum value)
        {
            FieldInfo field = value.GetType().GetField(value.ToString());

            if (field == null)
            {
                return(value.AsId().ToString());
            }
            var attributes = field.GetCustomAttributes(typeof(DescriptionAttribute), false)
                             as DescriptionAttribute[];

            return(attributes.Length > 0 ? attributes[0].Description : string.Empty);
        }