QiFeng.ZWY.Utility/DataHelper/EnumUtil.cs

(开头部分) 5KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Web.Mvc;
using System.Web.WebPages.Html;

namespace QiFeng.LMSD.Utility
{
    /// <summary>
    /// EnumUtil
    /// </summary>
    public static class EnumUtil
    {
        private static readonly Hashtable htCache = Hashtable.Synchronized(new Hashtable());

        public static int GetValue(this System.Enum obj)
        {
            return obj.GetHashCode();
        }

        /// <summary>
        /// 获取枚举对应的Description内容
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static IList<KeyValuePair<string, string>> GetEnumDescriptions(Type type)
        {
            if (htCache.Contains(type))
                return htCache[type] as IList<KeyValuePair<string, string>>;
            IList<KeyValuePair<string, string>> dict = GetDictionary(type);
            htCache[type] = dict;
            return dict;
        }

        private static IList<KeyValuePair<string, string>> GetDictionary(Type type)
        {
            FieldInfo[] fields = type.GetFields();
            IList<KeyValuePair<string, string>> dict = new List<KeyValuePair<string, string>>();
            for (int i = 1; i < fields.Length; i++)
            {
                FieldInfo item = fields[i];
                string desription;
                object[] objs = item.GetCustomAttributes(typeof(DescriptionAttribute), false);
                if (objs != null && objs.Length != 0)
                {
                    DescriptionAttribute da = (DescriptionAttribute)objs[0];
                    desription = da.Description;
                }
                else
                {
                    desription = item.Name;
                }
                dict.Add(new KeyValuePair<string, string>(((int)Enum.Parse(type, item.Name)).ToString(), desription));
            }
            return dict;
        }

后面还有 98 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。