// MonoGame - Copyright (C) The MonoGame Team // This file is subject to the terms and conditions defined in // file 'LICENSE.txt', which is part of this source code package. using System; using System.Collections; using System.Collections.Generic; namespace Microsoft.Xna.Framework.Content.Pipeline { public class NamedValueDictionary : IDictionary { readonly Dictionary dict = new Dictionary(); /// /// Initializes an instance of NamedValueDictionary. /// public NamedValueDictionary() { } /// /// Adds the specified key and value to the dictionary. /// /// Identity of the key of the new data pair. /// The value of the new data pair. public void Add(string key, T value) { dict.Add(key, value); } /// /// Determines whether the specified key is present in the dictionary. /// /// Identity of a key. /// public bool ContainsKey(string key) { return dict.ContainsKey(key); } /// /// Gets all keys contained in the dictionary. /// public ICollection Keys { get { return dict.Keys; } } /// /// Removes the specified key and value from the dictionary. /// /// Identity of the key to be removed. /// true if the value is present; false otherwise. public bool Remove(string key) { return dict.Remove(key); } /// /// Gets the value associated with the specified key. /// /// Identity of the key of the element whose value is to be retrieved. /// The current value of the element. /// true if the value is present; false otherwise. public bool TryGetValue(string key, out T value) { return dict.TryGetValue(key, out value); } /// /// Specifies the type hint for the intermediate serializer. Values of this type do not store an explicit type attribute in the related XML source. /// protected internal virtual Type DefaultSerializerType { get { return typeof(T); } } /// /// Gets all values contained in the dictionary. /// public ICollection Values { get { return dict.Values; } } /// /// Gets or sets the specified item. /// /// Identity of a key. public T this[string key] { get { return dict[key]; } set { dict[key] = value; } } /// /// Adds an item to the collection. /// /// The item to add to the collection. void ICollection>.Add(KeyValuePair item) { ((ICollection>)dict).Add(item); } /// /// Removes all keys and values from the dictionary. /// public void Clear() { dict.Clear(); } /// /// Determines whether the collection contains a specific value. /// /// The object to locate in the collection. /// true if the collection contains the object; false otherwise. bool ICollection>.Contains(KeyValuePair item) { return ((ICollection>)dict).Contains(item); } /// /// Copies the elements of the collection to an array, starting at a specified index. /// /// The destination array. /// The index at which to begin the copy. void ICollection>.CopyTo(KeyValuePair[] array, int arrayIndex) { ((ICollection>)dict).CopyTo(array, arrayIndex); } /// /// Gets the number of items in the dictionary. /// public int Count { get { return dict.Count; } } /// /// Gets a value indicating if this object is read-only. /// bool ICollection>.IsReadOnly { get { return false; } } /// /// Removes the first occurrence of the specified object from the collection. /// /// The item to remove from the collection. /// true if the item was successfully removed from the collection; false otherwise. bool ICollection>.Remove(KeyValuePair item) { return ((ICollection>)dict).Remove(item); } /// /// Gets an enumerator that iterates through items in a dictionary. /// /// Enumerator for iterating through the dictionary. public IEnumerator> GetEnumerator() { return dict.GetEnumerator(); } /// /// Returns an enumerator that can iterate through this collection. /// /// An enumerator that can iterate through this collection IEnumerator IEnumerable.GetEnumerator() { return dict.GetEnumerator(); } /// /// Adds an element to the dictionary. /// /// Identity of the key of the new element. /// The value of the new element. protected virtual void AddItem(string key, T value) { dict.Add(key, value); } /// /// Removes all elements from the dictionary. /// protected virtual void ClearItems() { dict.Clear(); } /// /// Removes the specified element from the dictionary. /// /// Identity of the key of the data pair to be removed. /// true if the value is present; false otherwise. protected virtual bool RemoveItem(string key) { return dict.Remove(key); } /// /// Modifies the value of an existing element. /// /// Identity of the element to be modified. /// The value to be set. protected virtual void SetItem(string key, T value) { dict[key] = value; } } }