1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
5
using System.Collections.Generic;
7
namespace ICSharpCode.SharpDevelop.Dom
10
/// Wraps a IDictonary, allowing only the read-only operations.
12
sealed class ReadOnlyDictionary<TKey, TValue> : IDictionary<TKey, TValue>
14
IDictionary<TKey, TValue> baseDictionary;
16
public ReadOnlyDictionary(IDictionary<TKey, TValue> baseDictionary)
18
if (baseDictionary == null)
19
throw new ArgumentNullException("baseDictionary");
20
this.baseDictionary = baseDictionary;
23
public TValue this[TKey key] {
24
get { return baseDictionary[key]; }
25
set { throw new NotSupportedException(); }
28
public ICollection<TKey> Keys {
29
get { return baseDictionary.Keys; }
32
public ICollection<TValue> Values {
33
get { return baseDictionary.Values; }
37
get { return baseDictionary.Count; }
40
public bool IsReadOnly {
44
public bool ContainsKey(TKey key)
46
return baseDictionary.ContainsKey(key);
49
public void Add(TKey key, TValue value)
51
throw new NotSupportedException();
54
public bool Remove(TKey key)
56
throw new NotSupportedException();
59
public bool TryGetValue(TKey key, out TValue value)
61
return baseDictionary.TryGetValue(key, out value);
64
public void Add(KeyValuePair<TKey, TValue> item)
66
throw new NotSupportedException();
71
throw new NotSupportedException();
74
public bool Contains(KeyValuePair<TKey, TValue> item)
76
return baseDictionary.Contains(item);
79
public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
81
throw new NotSupportedException();
84
public bool Remove(KeyValuePair<TKey, TValue> item)
86
throw new NotSupportedException();
89
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
91
return baseDictionary.GetEnumerator();
94
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
96
return baseDictionary.GetEnumerator();