using System.Collections.Concurrent; using WingServerCommon.Config.Parameters; namespace WingServerCommon.Config { public class CommonConfigManager { private static ConcurrentDictionary> _parametersDictionary = new ConcurrentDictionary>(); public static void AddParamters(string key, string path) { var _parameters = ParameterSerializer.Deserialize(path); _parametersDictionary.AddOrUpdate(key, _parameters, (k, oldParameters) => _parameters); } /// /// 获取缓存信息 /// /// /// public static IEnumerable Get(string key) { if (_parametersDictionary.TryGetValue(key, out IEnumerable obj)) { return obj; } return default; } /// /// Get parameter by specifed section name and parameter name /// /// public static T GetParammeter(string key, string sectionName, string paramName) where T : class { var _parameters = Get(key); var parameter = _parameters.FirstOrDefault(x => x.Section == sectionName && x.Name == paramName) as T; if (parameter != null) { return parameter; } throw new System.ArgumentException($"{sectionName} - {paramName} not set correct"); } } }