/// <summary> /// Clear the global context properties /// </summary> public void Clear() { lock (m_syncRoot) { m_readOnlyProperties = new ReadOnlyPropertiesDictionary(); } }
/// <summary> /// Copy Constructor /// </summary> /// <param name="propertiesDictionary">properties to copy</param> /// <remarks> /// <para> /// Initializes a new instance of the <see cref="T:log4net.Util.ReadOnlyPropertiesDictionary" /> class. /// </para> /// </remarks> public ReadOnlyPropertiesDictionary(ReadOnlyPropertiesDictionary propertiesDictionary) { foreach (DictionaryEntry item in (IEnumerable)propertiesDictionary) { InnerHashtable.Add(item.Key, item.Value); } }
/// <summary> /// Copy Constructor /// </summary> /// <param name="propertiesDictionary">properties to copy</param> /// <remarks> /// <para> /// Initializes a new instance of the <see cref="ReadOnlyPropertiesDictionary" /> class. /// </para> /// </remarks> public ReadOnlyPropertiesDictionary(ReadOnlyPropertiesDictionary propertiesDictionary) { foreach (DictionaryEntry entry in propertiesDictionary) { InnerHashtable.Add(entry.Key, entry.Value); } }
/// <summary> /// Copy Constructor /// </summary> /// <param name="propertiesDictionary">properties to copy</param> /// <remarks> /// <para> /// Initializes a new instance of the <see cref="ReadOnlyPropertiesDictionary" /> class. /// </para> /// </remarks> public ReadOnlyPropertiesDictionary(ReadOnlyPropertiesDictionary propertiesDictionary) { foreach(DictionaryEntry entry in propertiesDictionary) { InnerHashtable.Add(entry.Key, entry.Value); } }
public PropertiesDictionary Flatten() { if (this.m_flattened == null) { this.m_flattened = new PropertiesDictionary(); int count = this.m_nestedProperties.Count; while (--count >= 0) { ReadOnlyPropertiesDictionary dictionary = (ReadOnlyPropertiesDictionary)this.m_nestedProperties[count]; IEnumerator enumerator = ((IEnumerable)dictionary).GetEnumerator(); try { while (enumerator.MoveNext()) { DictionaryEntry current = (DictionaryEntry)enumerator.Current; this.m_flattened[(string)current.Key] = current.Value; } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } } } return(this.m_flattened); }
public void Remove(string key) { lock (this.m_syncRoot) { if (this.m_readOnlyProperties.Contains(key)) { PropertiesDictionary propertiesDictionary = new PropertiesDictionary(this.m_readOnlyProperties); propertiesDictionary.Remove(key); this.m_readOnlyProperties = new ReadOnlyPropertiesDictionary(propertiesDictionary); } } }
/// <summary> /// Remove a property from the global context /// </summary> /// <param name="key">the key for the entry to remove</param> /// <remarks> /// <para> /// Removing an entry from the global context properties is relatively expensive compared /// with reading a value. /// </para> /// </remarks> public void Remove(string key) { lock (m_syncRoot) { if (m_readOnlyProperties.Contains(key)) { PropertiesDictionary mutableProps = new PropertiesDictionary(m_readOnlyProperties); mutableProps.Remove(key); m_readOnlyProperties = new ReadOnlyPropertiesDictionary(mutableProps); } } }
/// <summary> /// Gets or sets the value of a property /// </summary> /// <value> /// The value for the property with the specified key /// </value> /// <remarks> /// <para> /// Reading the value for a key is faster than setting the value. /// When the value is written a new read only copy of /// the properties is created. /// </para> /// </remarks> public override object this[string key] { get { return(m_readOnlyProperties[key]); } set { lock (m_syncRoot) { var mutableProps = new PropertiesDictionary(m_readOnlyProperties); mutableProps[key] = value; m_readOnlyProperties = new ReadOnlyPropertiesDictionary(mutableProps); } } }
/// <summary> /// Flatten this composite collection into a single properties dictionary /// </summary> /// <returns>the flattened dictionary</returns> /// <remarks> /// <para> /// Reduces the collection of ordered dictionaries to a single dictionary /// containing the resultant values for the keys. /// </para> /// </remarks> public PropertiesDictionary Flatten() { if (m_flattened == null) { m_flattened = new PropertiesDictionary(); for (int i = m_nestedProperties.Count; --i >= 0;) { ReadOnlyPropertiesDictionary cur = (ReadOnlyPropertiesDictionary)m_nestedProperties[i]; foreach (DictionaryEntry entry in cur) { m_flattened[(string)entry.Key] = entry.Value; } } } return(m_flattened); }
public object this[string key] { get { object obj2; if (this.m_flattened != null) { return(this.m_flattened[key]); } IEnumerator enumerator = this.m_nestedProperties.GetEnumerator(); try { while (true) { if (enumerator.MoveNext()) { ReadOnlyPropertiesDictionary current = (ReadOnlyPropertiesDictionary)enumerator.Current; if (!current.Contains(key)) { continue; } obj2 = current[key]; } else { return(null); } break; } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } return(obj2); } }
public ReadOnlyPropertiesDictionary(ReadOnlyPropertiesDictionary propertiesDictionary) { this.m_hashtable = new Hashtable(); IEnumerator enumerator = ((IEnumerable)propertiesDictionary).GetEnumerator(); try { while (enumerator.MoveNext()) { DictionaryEntry current = (DictionaryEntry)enumerator.Current; this.InnerHashtable.Add(current.Key, current.Value); } } finally { IDisposable disposable = enumerator as IDisposable; if (disposable != null) { disposable.Dispose(); } } }
/// <summary> /// Add a Properties Dictionary to this composite collection /// </summary> /// <param name="properties">the properties to add</param> /// <remarks> /// <para> /// Properties dictionaries added first take precedence over dictionaries added /// later. /// </para> /// </remarks> public void Add(ReadOnlyPropertiesDictionary properties) { m_flattened = null; m_nestedProperties.Add(properties); }
/// <summary> /// Constructor /// </summary> /// <param name="propertiesDictionary">properties to copy</param> /// <remarks> /// <para> /// Initializes a new instance of the <see cref="PropertiesDictionary" /> class. /// </para> /// </remarks> public PropertiesDictionary(ReadOnlyPropertiesDictionary propertiesDictionary) : base(propertiesDictionary) { }
/// <summary> /// Remove a property from the global context /// </summary> /// <param name="key">the key for the entry to remove</param> /// <remarks> /// <para> /// Removing an entry from the global context properties is relatively expensive compared /// with reading a value. /// </para> /// </remarks> public void Remove(string key) { lock (m_syncRoot) { if (m_readOnlyProperties.Contains(key)) { var mutableProps = new PropertiesDictionary(m_readOnlyProperties); mutableProps.Remove(key); m_readOnlyProperties = new ReadOnlyPropertiesDictionary(mutableProps); } } }
/// <summary> /// Gets or sets the value of a property /// </summary> /// <value> /// The value for the property with the specified key /// </value> /// <remarks> /// <para> /// Reading the value for a key is faster than setting the value. /// When the value is written a new read only copy of /// the properties is created. /// </para> /// </remarks> public override object this[string key] { get { return m_readOnlyProperties[key]; } set { lock (m_syncRoot) { var mutableProps = new PropertiesDictionary(m_readOnlyProperties); mutableProps[key] = value; m_readOnlyProperties = new ReadOnlyPropertiesDictionary(mutableProps); } } }