~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/ReadOnlyDictionary.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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)
 
3
 
 
4
using System;
 
5
using System.Collections.Generic;
 
6
 
 
7
namespace ICSharpCode.SharpDevelop.Dom
 
8
{
 
9
        /// <summary>
 
10
        /// Wraps a IDictonary, allowing only the read-only operations.
 
11
        /// </summary>
 
12
        sealed class ReadOnlyDictionary<TKey, TValue> : IDictionary<TKey, TValue>
 
13
        {
 
14
                IDictionary<TKey, TValue> baseDictionary;
 
15
                
 
16
                public ReadOnlyDictionary(IDictionary<TKey, TValue> baseDictionary)
 
17
                {
 
18
                        if (baseDictionary == null)
 
19
                                throw new ArgumentNullException("baseDictionary");
 
20
                        this.baseDictionary = baseDictionary;
 
21
                }
 
22
                
 
23
                public TValue this[TKey key] {
 
24
                        get { return baseDictionary[key]; }
 
25
                        set { throw new NotSupportedException(); }
 
26
                }
 
27
                
 
28
                public ICollection<TKey> Keys {
 
29
                        get { return baseDictionary.Keys; }
 
30
                }
 
31
                
 
32
                public ICollection<TValue> Values {
 
33
                        get { return baseDictionary.Values; }
 
34
                }
 
35
                
 
36
                public int Count {
 
37
                        get { return baseDictionary.Count; }
 
38
                }
 
39
                
 
40
                public bool IsReadOnly {
 
41
                        get { return true; }
 
42
                }
 
43
                
 
44
                public bool ContainsKey(TKey key)
 
45
                {
 
46
                        return baseDictionary.ContainsKey(key);
 
47
                }
 
48
                
 
49
                public void Add(TKey key, TValue value)
 
50
                {
 
51
                        throw new NotSupportedException();
 
52
                }
 
53
                
 
54
                public bool Remove(TKey key)
 
55
                {
 
56
                        throw new NotSupportedException();
 
57
                }
 
58
                
 
59
                public bool TryGetValue(TKey key, out TValue value)
 
60
                {
 
61
                        return baseDictionary.TryGetValue(key, out value);
 
62
                }
 
63
                
 
64
                public void Add(KeyValuePair<TKey, TValue> item)
 
65
                {
 
66
                        throw new NotSupportedException();
 
67
                }
 
68
                
 
69
                public void Clear()
 
70
                {
 
71
                        throw new NotSupportedException();
 
72
                }
 
73
                
 
74
                public bool Contains(KeyValuePair<TKey, TValue> item)
 
75
                {
 
76
                        return baseDictionary.Contains(item);
 
77
                }
 
78
                
 
79
                public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
 
80
                {
 
81
                        throw new NotSupportedException();
 
82
                }
 
83
                
 
84
                public bool Remove(KeyValuePair<TKey, TValue> item)
 
85
                {
 
86
                        throw new NotSupportedException();
 
87
                }
 
88
                
 
89
                public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
 
90
                {
 
91
                        return baseDictionary.GetEnumerator();
 
92
                }
 
93
                
 
94
                System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
 
95
                {
 
96
                        return baseDictionary.GetEnumerator();
 
97
                }
 
98
        }
 
99
}