private void TestConfigurationAdd(IConfiguration conf) { long start = Environment.TickCount; for (int i = 0; i < 100000; i++) { conf.AddProperty("add-key" + i, "value"); } long duration = Environment.TickCount - start; Console.WriteLine("Add property for " + conf + " took " + duration + " ms"); }
/// <summary> /// Add or update the property in the underlying config depending on if it exists /// </summary> /// <param name="name"></param> /// <param name="newValue"></param> /// <param name="config"></param> public void AddOrChangeProperty(string name, object newValue, IConfiguration config) { // We do not want to abort the operation due to failed validation on one property try { if (!config.ContainsKey(name)) { m_Log.DebugFormat("Adding property key [{0}], value [{1}]", name, newValue); config.AddProperty(name, newValue); return; } var oldValue = config.GetProperty(name); if (newValue != null) { object newValueArray; if (oldValue is IList && config.ListDelimiter != '\0') { newValueArray = new ArrayList(); var values = ((string)newValue).Split(config.ListDelimiter).Select(v => v.Trim()).Where(v => v.Length != 0); foreach (var value in values) { ((IList)newValueArray).Add(value); } } else { newValueArray = newValue; } if (!ObjectUtils.AreEqual(newValueArray, oldValue)) { m_Log.DebugFormat("Updating property key [{0}], value [{1}]", name, newValue); config.SetProperty(name, newValue); } } else if (oldValue != null) { m_Log.DebugFormat("nulling out property key [{0}]", name); config.SetProperty(name, null); } } catch (ValidationException e) { m_Log.Warn("Validation failed for property " + name, e); } }
/// <summary> /// Add a property to the configuration. /// If it already exists then the value stated here will be added to the configuration entry. /// </summary> /// <param name="key">The key to add the property to.</param> /// <param name="value">The value to add.</param> public void AddProperty(string key, object value) { m_Config.AddProperty(key, value); }
public override void AddProperty(string key, object value) { _memoryConfiguration.AddProperty(key, value); }