예제 #1
0
        public static EnumDefInfo GetEnumDef(string enumKey, string category = "", string subCategory = "")
        {
            string key = enumKey;

            //从缓存中获取
            object obj = CacheHelper.Get(key);

            if (obj != null)
            {
                return(obj as EnumDefInfo);
            }

            DataRow enumDef = FormulaHelper.GetService <IEnumService>().GetEnumDefRow(enumKey);

            SQLHelper   baseSqlHelper = SQLHelper.CreateSqlHelper("Base");
            EnumDefInfo result        = new EnumDefInfo()
            {
                ID          = enumDef["ID"].ToString(),
                Code        = enumDef["Code"].ToString(),
                Name        = enumDef["Name"].ToString(),
                Description = enumDef["Description"].ToString()
            };
            DataTable dt = GetEnumTable(key, category, subCategory);

            result.EnumItem = GetEnumItemSet(dt);
            //缓存
            CacheHelper.Set(key, result);


            return(result);
        }
예제 #2
0
        public static EnumDefInfo GetEnumDef(Type emType)
        {
            string key = string.Format("enum_{0}", emType.Name);;

            //从缓存中获取
            object obj = CacheHelper.Get(key);

            if (obj != null)
            {
                return(obj as EnumDefInfo);
            }


            object[] arr         = emType.GetCustomAttributes(typeof(DescriptionAttribute), true);
            string   description = arr.Length > 0 ? ((DescriptionAttribute)arr[0]).Description : emType.Name;

            EnumDefInfo enumDef = new EnumDefInfo()
            {
                Code = emType.Name, Name = emType.Name, Description = description
            };

            DataTable dt = GetEnumTable(emType);

            enumDef.EnumItem = GetEnumItemSet(dt);

            CacheHelper.Set(key, enumDef);
            return(enumDef);
        }