//----------------------------------------------------------------------- // // Copyright (c) Outercurve Foundation. All rights reserved. // //----------------------------------------------------------------------- namespace DotNetOpenAuth.Messaging { using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; /// /// An empty dictionary. Useful for avoiding memory allocations in creating new dictionaries to represent empty ones. /// /// The type of the key. /// The type of the value. [Serializable] internal class EmptyDictionary : IDictionary { /// /// The singleton instance of the empty dictionary. /// internal static readonly EmptyDictionary Instance = new EmptyDictionary(); /// /// Prevents a default instance of the EmptyDictionary class from being created. /// private EmptyDictionary() { } /// /// Gets an containing the values in the . /// /// /// /// An containing the values in the object that implements . /// public ICollection Values { get { return EmptyList.Instance; } } /// /// Gets the number of elements contained in the . /// /// /// /// The number of elements contained in the . /// public int Count { get { return 0; } } /// /// Gets a value indicating whether the is read-only. /// /// /// true if the is read-only; otherwise, false. /// public bool IsReadOnly { get { return true; } } /// /// Gets an containing the keys of the . /// /// /// /// An containing the keys of the object that implements . /// public ICollection Keys { get { return EmptyList.Instance; } } /// /// Gets or sets the value with the specified key. /// /// The key being read or written. /// Nothing. It always throws. public TValue this[TKey key] { get { throw new KeyNotFoundException(); } set { throw new NotSupportedException(); } } /// /// Adds an element with the provided key and value to the . /// /// The object to use as the key of the element to add. /// The object to use as the value of the element to add. /// /// is null. /// /// /// An element with the same key already exists in the . /// /// /// The is read-only. /// public void Add(TKey key, TValue value) { throw new NotSupportedException(); } /// /// Determines whether the contains an element with the specified key. /// /// The key to locate in the . /// /// true if the contains an element with the key; otherwise, false. /// /// /// is null. /// public bool ContainsKey(TKey key) { return false; } /// /// Removes the element with the specified key from the . /// /// The key of the element to remove. /// /// true if the element is successfully removed; otherwise, false. This method also returns false if was not found in the original . /// /// /// is null. /// /// /// The is read-only. /// public bool Remove(TKey key) { return false; } /// /// Gets the value associated with the specified key. /// /// The key whose value to get. /// When this method returns, the value associated with the specified key, if the key is found; otherwise, the default value for the type of the parameter. This parameter is passed uninitialized. /// /// true if the object that implements contains an element with the specified key; otherwise, false. /// /// /// is null. /// public bool TryGetValue(TKey key, out TValue value) { value = default(TValue); return false; } #region ICollection> Members /// /// Adds an item to the . /// /// The object to add to the . /// /// The is read-only. /// [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Code Contracts ccrewrite does this.")] public void Add(KeyValuePair item) { throw new NotSupportedException(); } /// /// Removes all items from the . /// /// /// The is read-only. /// public void Clear() { throw new NotSupportedException(); } /// /// Determines whether the contains a specific value. /// /// The object to locate in the . /// /// true if is found in the ; otherwise, false. /// public bool Contains(KeyValuePair item) { return false; } /// /// Copies the elements of the to an , starting at a particular index. /// /// The one-dimensional that is the destination of the elements copied from . The must have zero-based indexing. /// The zero-based index in at which copying begins. /// /// is null. /// /// /// is less than 0. /// /// /// is multidimensional. /// -or- /// is equal to or greater than the length of . /// -or- /// The number of elements in the source is greater than the available space from to the end of the destination . /// -or- /// Type cannot be cast automatically to the type of the destination . /// public void CopyTo(KeyValuePair[] array, int arrayIndex) { } /// /// Removes the first occurrence of a specific object from the . /// /// The object to remove from the . /// /// true if was successfully removed from the ; otherwise, false. This method also returns false if is not found in the original . /// /// /// The is read-only. /// public bool Remove(KeyValuePair item) { return false; } #endregion #region IEnumerable> Members /// /// Returns an enumerator that iterates through the collection. /// /// /// A that can be used to iterate through the collection. /// public IEnumerator> GetEnumerator() { return Enumerable.Empty>().GetEnumerator(); } #endregion #region IEnumerable Members /// /// Returns an enumerator that iterates through a collection. /// /// /// An object that can be used to iterate through the collection. /// System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return EmptyEnumerator.Instance; } #endregion } }