//清空全部空闲 //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); }