1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using CommonLang.Property;
- using CommonLang;
- namespace CommonLang.Property
- {
- public class Catgorys
- {
- private List<Type> triggerTypes;
- private HashMap<string, List<TypeDescAttribute>> catgorysMap = new HashMap<string, List<TypeDescAttribute>>();
- private List<string> catgorysName = new List<string>();
- public Catgorys(Type baseType)
- {
- BaseType = baseType;
- triggerTypes = ReflectionUtil.GetNoneVirtualSubTypes(baseType);
- foreach (Type type in triggerTypes)
- {
- try
- {
- TypeDescAttribute tt = new TypeDescAttribute(type);
- List<TypeDescAttribute> catgorys = catgorysMap.Get(tt.Desc.Category);
- if (catgorys == null)
- {
- catgorys = new List<TypeDescAttribute>();
- catgorysName.Add(tt.Desc.Category);
- catgorysMap.Put(tt.Desc.Category, catgorys);
- }
- catgorys.Add(tt);
- }
- catch (Exception err)
- {
- Console.WriteLine("Catgorys catch: " + err);
- }
- }
- }
- public Type BaseType { get; private set; }
- public List<string> CatgoryNames { get { return catgorysName; } }
- public List<TypeDescAttribute> GetCatgoryTypes(string name)
- {
- return catgorysMap.Get(name);
- }
- /// <summary>
- /// 找到Type对应的TypeDescAttribute
- /// </summary>
- /// <param name="type"></param>
- /// <returns></returns>
- public TypeDescAttribute GetTypeDescAttribute(Type type)
- {
- DescAttribute desc = PropertyUtil.GetAttribute<DescAttribute>(type);
- if (desc != null)
- {
- List<TypeDescAttribute> catgorys = catgorysMap.Get(desc.Category);
- if (catgorys != null)
- {
- foreach (TypeDescAttribute ta in catgorys)
- {
- if (ta.DataType == type)
- {
- return ta;
- }
- }
- }
- }
- return null;
- }
- private static HashMap<Type, Catgorys> CatgorysMap = new HashMap<Type, Catgorys>();
- public static Catgorys GetCatgory(Type baseType)
- {
- Catgorys ret = CatgorysMap.Get(baseType);
- if (ret == null)
- {
- ret = new Catgorys(baseType);
- CatgorysMap.Put(baseType, ret);
- }
- return ret;
- }
- }
- }
|