1 // -----------------------------------------------------------------------
\r
2 // Copyright (c) Microsoft Corporation. All rights reserved.
\r
3 // -----------------------------------------------------------------------
\r
5 using System.Collections;
\r
6 using System.Collections.Generic;
\r
7 using System.Diagnostics;
\r
9 namespace Microsoft.Internal.Collections
\r
11 [DebuggerDisplay("Count = {Count}")]
\r
12 [DebuggerTypeProxy(typeof(ReadOnlyDictionaryDebuggerProxy<,>))]
\r
13 internal sealed partial class ReadOnlyDictionary<TKey, TValue> : IDictionary<TKey, TValue>
\r
15 private readonly IDictionary<TKey, TValue> _innerDictionary;
\r
17 public ReadOnlyDictionary(IDictionary<TKey, TValue> dictionary)
\r
19 this._innerDictionary = dictionary ?? new Dictionary<TKey, TValue>(0);
\r
24 get { return this._innerDictionary.Count; }
\r
27 public bool IsReadOnly
\r
29 get { return true; }
\r
32 public ICollection<TKey> Keys
\r
34 get { return this._innerDictionary.Keys; }
\r
37 public TValue this[TKey key]
\r
39 get { return this._innerDictionary[key]; }
\r
40 set { throw new NotSupportedException(Strings.NotSupportedReadOnlyDictionary); }
\r
43 public ICollection<TValue> Values
\r
45 get { return this._innerDictionary.Values; }
\r
48 public bool Contains(KeyValuePair<TKey, TValue> item)
\r
50 return this._innerDictionary.Contains(item);
\r
53 public bool ContainsKey(TKey key)
\r
55 return this._innerDictionary.ContainsKey(key);
\r
58 public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
\r
60 this._innerDictionary.CopyTo(array, arrayIndex);
\r
63 public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
\r
65 return this._innerDictionary.GetEnumerator();
\r
68 public bool TryGetValue(TKey key, out TValue value)
\r
70 return this._innerDictionary.TryGetValue(key, out value);
\r
73 IEnumerator IEnumerable.GetEnumerator()
\r
75 return this._innerDictionary.GetEnumerator();
\r
78 void IDictionary<TKey, TValue>.Add(TKey key, TValue value)
\r
80 throw new NotSupportedException(Strings.NotSupportedReadOnlyDictionary);
\r
83 void ICollection<KeyValuePair<TKey, TValue>>.Add(KeyValuePair<TKey, TValue> item)
\r
85 throw new NotSupportedException(Strings.NotSupportedReadOnlyDictionary);
\r
88 void ICollection<KeyValuePair<TKey, TValue>>.Clear()
\r
90 throw new NotSupportedException(Strings.NotSupportedReadOnlyDictionary);
\r
93 bool IDictionary<TKey, TValue>.Remove(TKey key)
\r
95 throw new NotSupportedException(Strings.NotSupportedReadOnlyDictionary);
\r
98 bool ICollection<KeyValuePair<TKey, TValue>>.Remove(KeyValuePair<TKey, TValue> item)
\r
100 throw new NotSupportedException(Strings.NotSupportedReadOnlyDictionary);
\r