c# 获取枚举的描述

1

        public static string GetText<T>(T msg)
        {
            object[] attrs = msg.GetType().GetField(msg.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), false);
            if (attrs != null && attrs.Length > 0)
            {
                return ((DescriptionAttribute)attrs[0]).Description;
            }
            return string.Empty;
        }

 

2

posted @ 2021-01-05 17:00  waityu  阅读(227)  评论(0编辑  收藏  举报