随笔 - 74,  文章 - 1,  评论 - 1,  阅读 - 44849
复制代码
        /// <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   不知勿言  阅读(75)  评论(0编辑  收藏  举报

< 2025年2月 >
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 1
2 3 4 5 6 7 8
点击右上角即可分享
微信分享提示