/// <summary> /// 读取配置 /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public static T GetInstance <T>() where T : class, new() { var t = typeof(T); string path = EnsurePathCache(t); DateTime lastWriteTime = File.GetLastWriteTime(path); ConfigCacheHelper configCache = null; if (m_ConfigCache.ContainsKey(t)) { configCache = m_ConfigCache[t]; } if (configCache == null || configCache.LastCacheTime != lastWriteTime) { lock (lockHelper) { T config = XmlSerializeHelper.Load <T>(path); configCache = new ConfigCacheHelper(lastWriteTime, config); m_ConfigCache[t] = configCache; } } return(configCache.Config as T); }
/// <summary> /// 设置配置 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="info"></param> public static void SetInstance <T>(T info) where T : new() { lock (lockHelper) { XmlSerializeHelper.Save(EnsurePathCache(info.GetType()), info); } }