//----------------------------------------------------------------------- // // Copyright (c) Outercurve Foundation. All rights reserved. // //----------------------------------------------------------------------- namespace DotNetOpenAuth.Messaging { using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; /// /// An empty, read-only list. /// /// The type the list claims to include. [Serializable] internal class EmptyList : IList { /// /// The singleton instance of the empty list. /// internal static readonly EmptyList Instance = new EmptyList(); /// /// Prevents a default instance of the EmptyList class from being created. /// private EmptyList() { } /// /// 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; } } #region IList Members /// /// Gets or sets the at the specified index. /// /// The index of the element in the list to change. /// Nothing. It always throws. public T this[int index] { get { throw new ArgumentOutOfRangeException("index"); } set { throw new ArgumentOutOfRangeException("index"); } } /// /// Determines the index of a specific item in the . /// /// The object to locate in the . /// /// The index of if found in the list; otherwise, -1. /// public int IndexOf(T item) { return -1; } /// /// Inserts an item to the at the specified index. /// /// The zero-based index at which should be inserted. /// The object to insert into the . /// /// is not a valid index in the . /// /// /// The is read-only. /// public void Insert(int index, T item) { throw new NotSupportedException(); } /// /// Removes the item at the specified index. /// /// The zero-based index of the item to remove. /// /// is not a valid index in the . /// /// /// The is read-only. /// [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Code Contracts ccrewrite does this.")] public void RemoveAt(int index) { throw new ArgumentOutOfRangeException("index"); } #endregion #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(T 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(T 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(T[] 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(T 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 System.Linq.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 } }