Added the XrdsPublisher ASP.NET control.
[dotnetoauth.git] / src / DotNetOpenAuth / Messaging / EmptyDictionary.cs
blobdf2f5a75e3e16a6497fab92b81248a80dedd5805
1 //-----------------------------------------------------------------------
2 // <copyright file="EmptyDictionary.cs" company="Andrew Arnott">
3 // Copyright (c) Andrew Arnott. All rights reserved.
4 // </copyright>
5 //-----------------------------------------------------------------------
7 namespace DotNetOpenAuth.Messaging {
8 using System;
9 using System.Collections.Generic;
10 using System.Linq;
12 /// <summary>
13 /// An empty dictionary. Useful for avoiding memory allocations in creating new dictionaries to represent empty ones.
14 /// </summary>
15 /// <typeparam name="TKey">The type of the key.</typeparam>
16 /// <typeparam name="TValue">The type of the value.</typeparam>
17 internal class EmptyDictionary<TKey, TValue> : IDictionary<TKey, TValue> {
18 /// <summary>
19 /// The singleton instance of the empty dictionary.
20 /// </summary>
21 internal static readonly EmptyDictionary<TKey, TValue> Instance = new EmptyDictionary<TKey, TValue>();
23 /// <summary>
24 /// Prevents a default instance of the EmptyDictionary class from being created.
25 /// </summary>
26 private EmptyDictionary() {
29 /// <summary>
30 /// Gets an <see cref="T:System.Collections.Generic.ICollection`1"/> containing the values in the <see cref="T:System.Collections.Generic.IDictionary`2"/>.
31 /// </summary>
32 /// <value></value>
33 /// <returns>
34 /// An <see cref="T:System.Collections.Generic.ICollection`1"/> containing the values in the object that implements <see cref="T:System.Collections.Generic.IDictionary`2"/>.
35 /// </returns>
36 public ICollection<TValue> Values {
37 get { return EmptyList<TValue>.Instance; }
40 /// <summary>
41 /// Gets the number of elements contained in the <see cref="T:System.Collections.Generic.ICollection`1"/>.
42 /// </summary>
43 /// <value></value>
44 /// <returns>
45 /// The number of elements contained in the <see cref="T:System.Collections.Generic.ICollection`1"/>.
46 /// </returns>
47 public int Count {
48 get { return 0; }
51 /// <summary>
52 /// Gets a value indicating whether the <see cref="T:System.Collections.Generic.ICollection`1"/> is read-only.
53 /// </summary>
54 /// <value></value>
55 /// <returns>true if the <see cref="T:System.Collections.Generic.ICollection`1"/> is read-only; otherwise, false.
56 /// </returns>
57 public bool IsReadOnly {
58 get { return true; }
61 /// <summary>
62 /// Gets an <see cref="T:System.Collections.Generic.ICollection`1"/> containing the keys of the <see cref="T:System.Collections.Generic.IDictionary`2"/>.
63 /// </summary>
64 /// <value></value>
65 /// <returns>
66 /// An <see cref="T:System.Collections.Generic.ICollection`1"/> containing the keys of the object that implements <see cref="T:System.Collections.Generic.IDictionary`2"/>.
67 /// </returns>
68 public ICollection<TKey> Keys {
69 get { return EmptyList<TKey>.Instance; }
72 /// <summary>
73 /// Gets or sets the value with the specified key.
74 /// </summary>
75 /// <param name="key">The key being read or written.</param>
76 public TValue this[TKey key] {
77 get { throw new KeyNotFoundException(); }
78 set { throw new NotSupportedException(); }
81 /// <summary>
82 /// Adds an element with the provided key and value to the <see cref="T:System.Collections.Generic.IDictionary`2"/>.
83 /// </summary>
84 /// <param name="key">The object to use as the key of the element to add.</param>
85 /// <param name="value">The object to use as the value of the element to add.</param>
86 /// <exception cref="T:System.ArgumentNullException">
87 /// <paramref name="key"/> is null.
88 /// </exception>
89 /// <exception cref="T:System.ArgumentException">
90 /// An element with the same key already exists in the <see cref="T:System.Collections.Generic.IDictionary`2"/>.
91 /// </exception>
92 /// <exception cref="T:System.NotSupportedException">
93 /// The <see cref="T:System.Collections.Generic.IDictionary`2"/> is read-only.
94 /// </exception>
95 public void Add(TKey key, TValue value) {
96 throw new NotSupportedException();
99 /// <summary>
100 /// Determines whether the <see cref="T:System.Collections.Generic.IDictionary`2"/> contains an element with the specified key.
101 /// </summary>
102 /// <param name="key">The key to locate in the <see cref="T:System.Collections.Generic.IDictionary`2"/>.</param>
103 /// <returns>
104 /// true if the <see cref="T:System.Collections.Generic.IDictionary`2"/> contains an element with the key; otherwise, false.
105 /// </returns>
106 /// <exception cref="T:System.ArgumentNullException">
107 /// <paramref name="key"/> is null.
108 /// </exception>
109 public bool ContainsKey(TKey key) {
110 return false;
113 /// <summary>
114 /// Removes the element with the specified key from the <see cref="T:System.Collections.Generic.IDictionary`2"/>.
115 /// </summary>
116 /// <param name="key">The key of the element to remove.</param>
117 /// <returns>
118 /// true if the element is successfully removed; otherwise, false. This method also returns false if <paramref name="key"/> was not found in the original <see cref="T:System.Collections.Generic.IDictionary`2"/>.
119 /// </returns>
120 /// <exception cref="T:System.ArgumentNullException">
121 /// <paramref name="key"/> is null.
122 /// </exception>
123 /// <exception cref="T:System.NotSupportedException">
124 /// The <see cref="T:System.Collections.Generic.IDictionary`2"/> is read-only.
125 /// </exception>
126 public bool Remove(TKey key) {
127 return false;
130 /// <summary>
131 /// Gets the value associated with the specified key.
132 /// </summary>
133 /// <param name="key">The key whose value to get.</param>
134 /// <param name="value">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 <paramref name="value"/> parameter. This parameter is passed uninitialized.</param>
135 /// <returns>
136 /// true if the object that implements <see cref="T:System.Collections.Generic.IDictionary`2"/> contains an element with the specified key; otherwise, false.
137 /// </returns>
138 /// <exception cref="T:System.ArgumentNullException">
139 /// <paramref name="key"/> is null.
140 /// </exception>
141 public bool TryGetValue(TKey key, out TValue value) {
142 value = default(TValue);
143 return false;
146 #region ICollection<KeyValuePair<TKey,TValue>> Members
148 /// <summary>
149 /// Adds an item to the <see cref="T:System.Collections.Generic.ICollection`1"/>.
150 /// </summary>
151 /// <param name="item">The object to add to the <see cref="T:System.Collections.Generic.ICollection`1"/>.</param>
152 /// <exception cref="T:System.NotSupportedException">
153 /// The <see cref="T:System.Collections.Generic.ICollection`1"/> is read-only.
154 /// </exception>
155 public void Add(KeyValuePair<TKey, TValue> item) {
156 throw new NotSupportedException();
159 /// <summary>
160 /// Removes all items from the <see cref="T:System.Collections.Generic.ICollection`1"/>.
161 /// </summary>
162 /// <exception cref="T:System.NotSupportedException">
163 /// The <see cref="T:System.Collections.Generic.ICollection`1"/> is read-only.
164 /// </exception>
165 public void Clear() {
166 throw new NotSupportedException();
169 /// <summary>
170 /// Determines whether the <see cref="T:System.Collections.Generic.ICollection`1"/> contains a specific value.
171 /// </summary>
172 /// <param name="item">The object to locate in the <see cref="T:System.Collections.Generic.ICollection`1"/>.</param>
173 /// <returns>
174 /// true if <paramref name="item"/> is found in the <see cref="T:System.Collections.Generic.ICollection`1"/>; otherwise, false.
175 /// </returns>
176 public bool Contains(KeyValuePair<TKey, TValue> item) {
177 return false;
180 /// <summary>
181 /// Copies the elements of the <see cref="T:System.Collections.Generic.ICollection`1"/> to an <see cref="T:System.Array"/>, starting at a particular <see cref="T:System.Array"/> index.
182 /// </summary>
183 /// <param name="array">The one-dimensional <see cref="T:System.Array"/> that is the destination of the elements copied from <see cref="T:System.Collections.Generic.ICollection`1"/>. The <see cref="T:System.Array"/> must have zero-based indexing.</param>
184 /// <param name="arrayIndex">The zero-based index in <paramref name="array"/> at which copying begins.</param>
185 /// <exception cref="T:System.ArgumentNullException">
186 /// <paramref name="array"/> is null.
187 /// </exception>
188 /// <exception cref="T:System.ArgumentOutOfRangeException">
189 /// <paramref name="arrayIndex"/> is less than 0.
190 /// </exception>
191 /// <exception cref="T:System.ArgumentException">
192 /// <paramref name="array"/> is multidimensional.
193 /// -or-
194 /// <paramref name="arrayIndex"/> is equal to or greater than the length of <paramref name="array"/>.
195 /// -or-
196 /// The number of elements in the source <see cref="T:System.Collections.Generic.ICollection`1"/> is greater than the available space from <paramref name="arrayIndex"/> to the end of the destination <paramref name="array"/>.
197 /// -or-
198 /// Type <paramref name="T"/> cannot be cast automatically to the type of the destination <paramref name="array"/>.
199 /// </exception>
200 public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex) {
203 /// <summary>
204 /// Removes the first occurrence of a specific object from the <see cref="T:System.Collections.Generic.ICollection`1"/>.
205 /// </summary>
206 /// <param name="item">The object to remove from the <see cref="T:System.Collections.Generic.ICollection`1"/>.</param>
207 /// <returns>
208 /// true if <paramref name="item"/> was successfully removed from the <see cref="T:System.Collections.Generic.ICollection`1"/>; otherwise, false. This method also returns false if <paramref name="item"/> is not found in the original <see cref="T:System.Collections.Generic.ICollection`1"/>.
209 /// </returns>
210 /// <exception cref="T:System.NotSupportedException">
211 /// The <see cref="T:System.Collections.Generic.ICollection`1"/> is read-only.
212 /// </exception>
213 public bool Remove(KeyValuePair<TKey, TValue> item) {
214 return false;
217 #endregion
219 #region IEnumerable<KeyValuePair<TKey,TValue>> Members
221 /// <summary>
222 /// Returns an enumerator that iterates through the collection.
223 /// </summary>
224 /// <returns>
225 /// A <see cref="T:System.Collections.Generic.IEnumerator`1"/> that can be used to iterate through the collection.
226 /// </returns>
227 public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator() {
228 return Enumerable.Empty<KeyValuePair<TKey, TValue>>().GetEnumerator();
231 #endregion
233 #region IEnumerable Members
235 /// <summary>
236 /// Returns an enumerator that iterates through a collection.
237 /// </summary>
238 /// <returns>
239 /// An <see cref="T:System.Collections.IEnumerator"/> object that can be used to iterate through the collection.
240 /// </returns>
241 System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
242 return EmptyEnumerator.Instance;
245 #endregion