C# 中 Enum使用特殊字符,重写ToString()

 

public enum EnumTest
    {
        [Description("等于")]
        等=1,
        [Description("小于")]
        小=2,
        [Description("大于")]
        大=3
    }
    public class EnumName
    {
        public static string GetEnumName(Enum en)
        {
            Type temType = en.GetType();
            MemberInfo[] memberInfos= temType.GetMember(en.ToString());
            if (memberInfos != null && memberInfos.Length > 0)
            {
                object[] objs= memberInfos[0].GetCustomAttributes(typeof(DescriptionAttribute), false);
                if (objs != null && objs.Length > 0)
                {
                    return ((DescriptionAttribute)objs[0]).Description;
                }
            }
            return en.ToString();
        }
    }

 

 

posted on 2010-03-18 10:22  漫步人生  阅读(5269)  评论(0编辑  收藏  举报