ScriptStack 1.0.4
Loading...
Searching...
No Matches
ReadOnlyDictionary.cs
Go to the documentation of this file.
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.Runtime.Serialization;
5using System.Text;
6
8{
9 [Serializable]
10 public class ReadOnlyDictionary<TKey, TValue>
11 : IDictionary<TKey, TValue>
12 , ICollection<KeyValuePair<TKey, TValue>>
13 , IEnumerable<KeyValuePair<TKey, TValue>>
14 , IDictionary
15 , ICollection
16 , IEnumerable
17 , ISerializable
18 , IDeserializationCallback
19 {
20 #region Private Members
21 private IDictionary<TKey, TValue> m_dictionaryTyped;
22 private IDictionary m_dictionary;
23
24 #endregion
25
26 #region Default Methods
27 IEnumerator IEnumerable.GetEnumerator()
28 {
29 return m_dictionary.GetEnumerator();
30 }
31 IDictionaryEnumerator IDictionary.GetEnumerator()
32 {
33 return m_dictionary.GetEnumerator();
34 }
35
36 #endregion
37
38 #region Default Properties
39 ICollection IDictionary.Keys
40 {
41 get
42 {
43 return m_dictionary.Keys;
44 }
45 }
46 ICollection IDictionary.Values
47 {
48 get
49 {
50 return m_dictionary.Values;
51 }
52 }
53
54 #endregion
55
56 #region Public Methods
57 public ReadOnlyDictionary(IDictionary<TKey, TValue> dictionaryToWrap)
58 {
59 m_dictionaryTyped = dictionaryToWrap;
60 m_dictionary = (IDictionary)m_dictionaryTyped;
61 }
62 public static ReadOnlyDictionary<TKey, TValue> AsReadOnly(IDictionary<TKey, TValue> dictionaryToWrap)
63 {
64 return new ReadOnlyDictionary<TKey, TValue>(dictionaryToWrap);
65 }
66 public void Add(TKey key, TValue value)
67 {
68 }
69 public bool ContainsKey(TKey key)
70 {
71 return m_dictionaryTyped.ContainsKey(key);
72 }
73 public bool Remove(TKey key)
74 {
75 return false;
76 }
77 public bool TryGetValue(TKey key, out TValue value)
78 {
79 return m_dictionaryTyped.TryGetValue(key, out value);
80 }
81 public void Add(KeyValuePair<TKey, TValue> item)
82 {
83 }
84 public void Clear()
85 {
86 }
87 public bool Contains(KeyValuePair<TKey, TValue> item)
88 {
89 return m_dictionaryTyped.Contains(item);
90 }
91 public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
92 {
93 m_dictionaryTyped.CopyTo(array, arrayIndex);
94 }
95 public bool Remove(KeyValuePair<TKey, TValue> item)
96 {
97 return false;
98 }
99 public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
100 {
101 return m_dictionaryTyped.GetEnumerator();
102 }
103 public void Add(object key, object value)
104 {
105 }
106 public bool Contains(object key)
107 {
108 return m_dictionary.Contains(key);
109 }
110 public void Remove(object key)
111 {
112 }
113 public object this[object key]
114 {
115 get
116 {
117 return m_dictionary[key];
118 }
119 set
120 {
121 }
122 }
123 public void CopyTo(Array array, int index)
124 {
125 }
126 public void OnDeserialization(object sender)
127 {
128 IDeserializationCallback callback = m_dictionaryTyped as IDeserializationCallback;
129 callback.OnDeserialization(sender);
130 }
131 public void GetObjectData(SerializationInfo info, StreamingContext context)
132 {
133 ISerializable serializable = m_dictionaryTyped as ISerializable;
134 serializable.GetObjectData(info, context);
135 }
136
137 #endregion
138
139 #region Public Methods
140 public ICollection<TKey> Keys
141 {
142 get
143 {
144 return ReadOnlyICollection<TKey>.AsReadOnly(m_dictionaryTyped.Keys);
145 }
146 }
147 public ICollection<TValue> Values
148 {
149 get
150 {
151 return ReadOnlyICollection<TValue>.AsReadOnly(m_dictionaryTyped.Values);
152 }
153 }
154 public int Count
155 {
156 get
157 {
158 return m_dictionaryTyped.Count;
159 }
160 }
161 public bool IsReadOnly
162 {
163 get
164 {
165 return true;
166 }
167 }
168 public TValue this[TKey key]
169 {
170 get
171 {
172 return m_dictionaryTyped[key];
173 }
174 set
175 {
176 }
177 }
178 public bool IsFixedSize
179 {
180 get
181 {
182 return m_dictionary.IsFixedSize;
183 }
184 }
185 public bool IsSynchronized
186 {
187 get
188 {
189 return m_dictionary.IsSynchronized;
190 }
191 }
192 public object SyncRoot
193 {
194 get
195 {
196 return m_dictionary.SyncRoot;
197 }
198 }
199
200 #endregion
201 }
202}
void Add(KeyValuePair< TKey, TValue > item)
bool Contains(KeyValuePair< TKey, TValue > item)
IEnumerator< KeyValuePair< TKey, TValue > > GetEnumerator()
bool TryGetValue(TKey key, out TValue value)
ReadOnlyDictionary(IDictionary< TKey, TValue > dictionaryToWrap)
bool Remove(KeyValuePair< TKey, TValue > item)
static ReadOnlyDictionary< TKey, TValue > AsReadOnly(IDictionary< TKey, TValue > dictionaryToWrap)
void GetObjectData(SerializationInfo info, StreamingContext context)
void CopyTo(KeyValuePair< TKey, TValue >[] array, int arrayIndex)