//清空全部空闲 //public void ClearAllIdles(Type type_) //{ // BasePool pool = GetPool(type_); // if (pool != null) // { // pool.ClearAllIdles(); // } //} //public void ClearAllIdles() //{ // if (m_type2pool.Count == 0) // return; // foreach (KeyValuePair<Type, ClassPool> kvp in m_type2pool) // { // ClassPool v = kvp.Value; // v.ClearAllIdles(); // } //} //清空对象池 public void Clear() { if (m_type2pool.Count > 0) { foreach (KeyValuePair <Type, TypePool> kvp in m_type2pool) { TypePool v = kvp.Value; v.Clear(); } m_type2pool.Clear(); } if (m_t2pool.Count > 0) { foreach (KeyValuePair <Type, object> kvp in m_t2pool) { ClassUtil.CallMethod(kvp.Value, "Clear"); } m_t2pool.Clear(); } if (m_id2pool.Count > 0) { foreach (KeyValuePair <string, BasePool> kvp in m_id2pool) { BasePool v = kvp.Value; v.Clear(); } m_id2pool.Clear(); } }
/// <summary> /// 解析配置文件 /// </summary> /// <param name="source_"></param> /// <param name="dataTp_"></param> /// <returns></returns> override public object[] Parse(object source_, Type dataTp_) { byte[] bytes = source_ as byte[]; MemoryStream fsRead = new MemoryStream(bytes); BinaryReader reader_ = new BinaryReader(fsRead); int tableDataLen = reader_.ReadInt32(); //读整形时,只要遇到10就出错。。 int dataLen = reader_.ReadInt32(); //int tableDataLen = (int)ReadValueFrom(reader_, CFG_PROPERTY_TP.INT); //int dataLen = (int)ReadValueFrom(reader_, CFG_PROPERTY_TP.INT); Type dataTp = dataTp_; object data; object[] datas = new object[tableDataLen]; string key; string tp; object value; for (int i = 0; i < tableDataLen; ++i) { data = Activator.CreateInstance(dataTp); for (int j = 0; j < dataLen; ++j) { key = ReadStrFrom(reader_); tp = ReadStrFrom(reader_); value = ReadValueFrom(reader_, tp); FieldInfo fieldInfo = dataTp.GetField(key); if (fieldInfo != null) { try { fieldInfo.SetValue(data, value); } catch { Log.Assert(false, "设置属性出错: " + key + " " + tp); reader_.Close(); return(null); } } } //尝试调用解析函数(用于在读取配置后进一步加工数据) ClassUtil.CallMethod(data, "Analyse"); datas[i] = data; } reader_.Close(); return(datas); }
//-------∽-★-∽------∽-★-∽--------∽-★-∽窗口预制相关∽-★-∽--------∽-★-∽------∽-★-∽--------// //创建窗口 protected IPop CreatePop(string popId_) { string url = CC_POP_ID.GetPrefebPath(popId_); if (string.IsNullOrEmpty(url)) { Log.Warn("窗口未注册: " + popId_); return(null); } IPop pop = ClassUtil.New(popId_) as IPop; pop.popID = popId_; return(pop); }
/// <summary> /// 获取单例, 有一定消耗, 尽量在低频调用时使用 /// </summary> /// <param name="type_"></param> /// <returns></returns> static public object Get(Type type_) { if (__tp2inst.ContainsKey(type_)) { return(__tp2inst[type_]); } object obj = ClassUtil.New(type_); if (obj != null) { __tp2inst[type_] = obj; } return(obj); }
/// <summary> /// 按属性排序 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="input_"></param> /// <param name="keyNames_">键名: string 或 string[] </param> /// <param name="sortOptions_">排序opt: ListSortOption 或 ListSortOption[] </param> /// <returns></returns> static public List <T> SortOn <T>(List <T> input_, object keyNames_, object sortOptions_ = null) { if (input_.Count == 1) { return(input_); } string[] names = null; if (keyNames_ is string) { names = new string[] { (string)keyNames_ }; } else if (keyNames_ is string[]) { names = keyNames_ as string[]; } if (names == null) { return(input_); } SortOption[] options; if (sortOptions_ is SortOption) { options = new SortOption[] { (SortOption)sortOptions_ }; } else if (sortOptions_ is SortOption[]) { options = sortOptions_ as SortOption[]; } else { options = new SortOption[] { SortOption.ASCENDING }; } Type type = typeof(T); //获取类型 string key; IComparable value1 = null; IComparable value2 = null; int compare = 0; SortOption opt = SortOption.ASCENDING; input_.Sort(delegate(T first, T second) { for (int i = 0; i < names.Length; ++i) { key = names[i]; value1 = ClassUtil.GetProperty(first, type, key) as IComparable; if (value1 == null) { continue; } value2 = ClassUtil.GetProperty(second, type, key) as IComparable; if (value2 == null) { continue; } if (i < options.Length) { opt = options[i]; //如果没有就取上一次 } compare = value1.CompareTo(value2); if (compare != 0) { if (opt == SortOption.ASCENDING) { return(compare); } else { return(-compare); } } } return(0); }); return(input_); }