public CachePool(int initCount = 0, int maxCount = 0, Object initParam = null, ILogger logger = null, Func <Object, TCacheItem> createCallback = null, string cacheName = null) { // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression if (string.IsNullOrEmpty(cacheName)) { /* * 派生类成员初始化 * 基类型成员初始化 * 基类型的构造函数 -> 调用虚拟成员 -> 会调用到派生类的虚拟成员 -> 可能这个派生类虚拟成员要在派生类型的构造函数中初始化,而因为现在调用还没有始化会出错。 * 派生类型的构造函数 */ // ReSharper disable once VirtualMemberCallInConstructor m_name = string.Concat("CachePool<", typeof(TCacheItem).Name, "-", GetHashCode(), ">"); } else { m_name = string.Concat("CachePool<", typeof(TCacheItem).Name, "-", cacheName, ">"); } if (logger == null) { logger = NoneLogger.Inst; } m_logger = logger; if (maxCount != 0) { if (initCount > maxCount) { initCount = maxCount; m_logger.LogWarning("initCount > maxCount", m_name + ".Ctor"); } m_pool = new Stack <PoolItem <TCacheItem> >(maxCount); m_usingList = new List <PoolItem <TCacheItem> >(maxCount); } else { m_pool = new Stack <PoolItem <TCacheItem> >(); m_usingList = new List <PoolItem <TCacheItem> >(); } m_maxCount = maxCount; m_initParam = initParam; m_createCallback = createCallback; m_tmpInfo = new CacheItemInfo <TCacheItem>(); for (int i = 0; i < initCount; i++) { PoolItem <TCacheItem> item = NewItem(); m_pool.Push(item); } }
/// <summary> /// 从字符串转值到u32 /// </summary> /// <param name="valueIn"></param> /// <param name="valueOut"></param> /// <param name="logger">默认值为null</param> /// <returns></returns> public static bool GetU32(string valueIn, out UInt32 valueOut, ILogger logger) { if (string.IsNullOrEmpty(valueIn)) { valueOut = 0; return(false); } bool success = UInt32.TryParse(valueIn, out valueOut); if (!success) { if (logger != null) { logger.LogError("UInt32.TryParse error", "StrHelper.GetU32"); } valueOut = 0; return(false); } return(true); }
/// <summary> /// 从字符串转值到float /// </summary> /// <param name="valueIn"></param> /// <param name="valueOut"></param> /// <param name="per">默认值为1</param> /// <param name="logger">默认值为null</param> /// <returns></returns> public static bool GetFloat(string valueIn, out float valueOut, float per, ILogger logger) { if (string.IsNullOrEmpty(valueIn)) { valueOut = 0; return(false); } bool success = float.TryParse(valueIn, out valueOut); if (!success) { if (logger != null) { logger.LogError("float.TryParse error", "StrHelper.GetFloat"); } valueOut = 0; return(false); } valueOut = valueOut * per; return(true); }