/// <summary>
        /// 获取枚举文本内容
        /// </summary>
        /// <param name="enum"></param>
        /// <returns></returns>
        public static string GetEnumDescription(this Enum @enum)
        {
            if (@enum == null)
            {
                return string.Empty;
            }
            Type enumType = @enum.GetType();
            var name = Enum.GetName(enumType, @enum);
            if (name == null)
                return string.Empty;
            var descAttr = enumType.GetField(name).GetCustomAttribute<System.ComponentModel.DescriptionAttribute>();
            return descAttr != null ? descAttr.Description : string.Empty;
        }

 

posted on 2021-08-09 11:30  不知勿言  阅读(74)  评论(0编辑  收藏  举报