/// <summary> /// 设定配置的值 /// </summary> /// <typeparam name="T">值的类型</typeparam> /// <param name="name">配置名</param> /// <param name="value">配置的值</param> public void Set <T>(string name, T value) { Guard.NotNull(name, "name"); if (locators.Count <= 0) { throw new RuntimeException("No Reg locator. please Reg() locator first."); } IConfigLocator configLocator = null; string val; foreach (var locator in locators) { if (locator.TryGetValue(name, out val)) { configLocator = locator; } } if (configLocator == null) { configLocator = locators.Last(); } ITypeStringConverter converter; if (!typeStringConverters.TryGetValue(typeof(T), out converter)) { throw new ConverterException("Can not find [" + typeof(T) + "] coverter impl."); } configLocator.Set(name, converter.ConvertToString(value)); }
/// <summary> /// 设定配置的值 /// </summary> /// <param name="name">配置名</param> /// <param name="value">配置的值</param> public void Set(string name, object value) { Guard.Requires <AssertException>(locator != null); Guard.Requires <AssertException>(converters != null); Guard.Requires <ArgumentNullException>(name != null); locator.Set(name, converters.Convert <string>(value)); List <Action <object> > watch; if (watches.TryGetValue(name, out watch)) { foreach (var callback in watch) { callback.Invoke(value); } } }