• C#枚举描述获取


     public static class EnumExtension
        {
            public static string GetDescription(this Enum value)
            {
                FieldInfo field = value.GetType().GetField(value.ToString());
                DescriptionAttribute attribute = Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)) as DescriptionAttribute;

                return attribute == null ? value.ToString() : attribute.Description;
            }

            //public static IEnumerable<EnumItem> GetDictionary<TEnum>(this TEnum tEnum)
            //    where TEnum : struct
            //{
            //    return Enum.GetValues(typeof(TEnum)).OfType<Enum>()
            //        .Select(x => new EnumItem
            //        {
            //            Key = Convert.ToInt32(x),
            //            Value = x.ToString(),
            //            Description = x.GetDescription()
            //        });
            //}

            public static IEnumerable<EnumItem> GetDictionary(Type tEnum)
            {
                return Enum.GetValues(tEnum).OfType<Enum>()
                    .Select(x => new EnumItem
                    {
                        Key = Convert.ToInt32(x),
                        Value = x.ToString(),
                        Description = x.GetDescription()
                    });
            }
        }

  • 相关阅读:
    android编译全过程
    Android APK反编译得到Java源代码和资源文件
    获取Android的Java源代码并在Eclipse中关联查看的最新方法《转载》
    定制ROM,添加apk文件报错。
    Ubuntu下下载编译android源码
    poj 2714 Random Walk
    hdu 3829 Cat VS Dog
    第九场组队赛总结
    2012 MUTC 9 总结
    hdu 1100 Trees Made to Order
  • 原文地址:https://www.cnblogs.com/guokun/p/5843421.html
Copyright © 2020-2023  润新知