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

原文地址:https://www.cnblogs.com/-7999/p/14236848.html