mscorlib(4.0.0.0) API with additions
DictionaryBase.cs
2 
3 namespace System.Collections
4 {
7  [ComVisible(true)]
9  {
10  private Hashtable hashtable;
11 
14  protected Hashtable InnerHashtable
15  {
16  get
17  {
18  if (hashtable == null)
19  {
20  hashtable = new Hashtable();
21  }
22  return hashtable;
23  }
24  }
25 
28  protected IDictionary Dictionary => this;
29 
32  public int Count
33  {
34  get
35  {
36  if (hashtable != null)
37  {
38  return hashtable.Count;
39  }
40  return 0;
41  }
42  }
43 
48  {
49  get
50  {
52  }
53  }
54 
58  bool IDictionary.IsFixedSize
59  {
60  get
61  {
63  }
64  }
65 
69  bool ICollection.IsSynchronized
70  {
71  get
72  {
74  }
75  }
76 
79  ICollection IDictionary.Keys
80  {
81  get
82  {
83  return InnerHashtable.Keys;
84  }
85  }
86 
89  object ICollection.SyncRoot
90  {
91  get
92  {
93  return InnerHashtable.SyncRoot;
94  }
95  }
96 
99  ICollection IDictionary.Values
100  {
101  get
102  {
103  return InnerHashtable.Values;
104  }
105  }
106 
113  object IDictionary.this[object key]
114  {
115  get
116  {
117  object obj = InnerHashtable[key];
118  OnGet(key, obj);
119  return obj;
120  }
121  set
122  {
123  OnValidate(key, value);
124  bool flag = true;
125  object obj = InnerHashtable[key];
126  if (obj == null)
127  {
128  flag = InnerHashtable.Contains(key);
129  }
130  OnSet(key, obj, value);
131  InnerHashtable[key] = value;
132  try
133  {
134  OnSetComplete(key, obj, value);
135  }
136  catch
137  {
138  if (flag)
139  {
140  InnerHashtable[key] = obj;
141  }
142  else
143  {
144  InnerHashtable.Remove(key);
145  }
146  throw;
147  }
148  }
149  }
150 
161  public void CopyTo(Array array, int index)
162  {
163  InnerHashtable.CopyTo(array, index);
164  }
165 
172  bool IDictionary.Contains(object key)
173  {
174  return InnerHashtable.Contains(key);
175  }
176 
184  void IDictionary.Add(object key, object value)
185  {
186  OnValidate(key, value);
187  OnInsert(key, value);
188  InnerHashtable.Add(key, value);
189  try
190  {
191  OnInsertComplete(key, value);
192  }
193  catch
194  {
195  InnerHashtable.Remove(key);
196  throw;
197  }
198  }
199 
201  public void Clear()
202  {
203  OnClear();
205  OnClearComplete();
206  }
207 
213  void IDictionary.Remove(object key)
214  {
215  if (InnerHashtable.Contains(key))
216  {
217  object value = InnerHashtable[key];
218  OnValidate(key, value);
219  OnRemove(key, value);
220  InnerHashtable.Remove(key);
221  try
222  {
223  OnRemoveComplete(key, value);
224  }
225  catch
226  {
227  InnerHashtable.Add(key, value);
228  throw;
229  }
230  }
231  }
232 
236  {
237  return InnerHashtable.GetEnumerator();
238  }
239 
243  {
244  return InnerHashtable.GetEnumerator();
245  }
246 
251  protected virtual object OnGet(object key, object currentValue)
252  {
253  return currentValue;
254  }
255 
260  protected virtual void OnSet(object key, object oldValue, object newValue)
261  {
262  }
263 
267  protected virtual void OnInsert(object key, object value)
268  {
269  }
270 
272  protected virtual void OnClear()
273  {
274  }
275 
279  protected virtual void OnRemove(object key, object value)
280  {
281  }
282 
286  protected virtual void OnValidate(object key, object value)
287  {
288  }
289 
294  protected virtual void OnSetComplete(object key, object oldValue, object newValue)
295  {
296  }
297 
301  protected virtual void OnInsertComplete(object key, object value)
302  {
303  }
304 
306  protected virtual void OnClearComplete()
307  {
308  }
309 
313  protected virtual void OnRemoveComplete(object key, object value)
314  {
315  }
316  }
317 }
virtual void OnInsertComplete(object key, object value)
Performs additional custom processes after inserting a new element into the T:System....
void CopyTo(Array array, int index)
Copies the T:System.Collections.DictionaryBase elements to a one-dimensional T:System....
virtual void OnRemoveComplete(object key, object value)
Performs additional custom processes after removing an element from the T:System.Collections....
virtual bool IsSynchronized
Gets a value indicating whether access to the T:System.Collections.Hashtable is synchronized (thread ...
Definition: Hashtable.cs:612
virtual void OnSet(object key, object oldValue, object newValue)
Performs additional custom processes before setting a value in the T:System.Collections....
Hashtable InnerHashtable
Gets the list of elements contained in the T:System.Collections.DictionaryBase instance.
object SyncRoot
Gets an object that can be used to synchronize access to the T:System.Collections....
Definition: ICollection.cs:23
IDictionaryEnumerator GetEnumerator()
Returns an T:System.Collections.IDictionaryEnumerator that iterates through the T:System....
virtual void Add(object key, object value)
Adds an element with the specified key and value into the T:System.Collections.Hashtable.
Definition: Hashtable.cs:916
bool Contains(object key)
Determines whether the T:System.Collections.IDictionary object contains an element with the specified...
void Clear()
Clears the contents of the T:System.Collections.DictionaryBase instance.
Definition: __Canon.cs:3
virtual void OnClear()
Performs additional custom processes before clearing the contents of the T:System....
virtual bool IsFixedSize
Gets a value indicating whether the T:System.Collections.Hashtable has a fixed size.
Definition: Hashtable.cs:607
int Count
Gets the number of elements contained in the T:System.Collections.DictionaryBase instance.
virtual ICollection Values
Gets an T:System.Collections.ICollection containing the values in the T:System.Collections....
Definition: Hashtable.cs:631
Exposes an enumerator, which supports a simple iteration over a non-generic collection....
Definition: IEnumerable.cs:9
virtual void CopyTo(Array array, int arrayIndex)
Copies the T:System.Collections.Hashtable elements to a one-dimensional T:System.Array instance at th...
Definition: Hashtable.cs:1084
Represents a collection of key/value pairs that are organized based on the hash code of the key....
Definition: Hashtable.cs:17
virtual ICollection Keys
Gets an T:System.Collections.ICollection containing the keys in the T:System.Collections....
Definition: Hashtable.cs:617
virtual void OnClearComplete()
Performs additional custom processes after clearing the contents of the T:System.Collections....
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition: Array.cs:17
void Remove(object key)
Removes the element with the specified key from the T:System.Collections.IDictionary object.
IDictionary Dictionary
Gets the list of elements contained in the T:System.Collections.DictionaryBase instance.
virtual void OnRemove(object key, object value)
Performs additional custom processes before removing an element from the T:System....
virtual void OnInsert(object key, object value)
Performs additional custom processes before inserting a new element into the T:System....
IEnumerator GetEnumerator()
Returns an enumerator that iterates through a collection.
virtual object SyncRoot
Gets an object that can be used to synchronize access to the T:System.Collections....
Definition: Hashtable.cs:645
virtual object OnGet(object key, object currentValue)
Gets the element with the specified key and value in the T:System.Collections.DictionaryBase instance...
virtual bool Contains(object key)
Determines whether the T:System.Collections.Hashtable contains a specific key.
Definition: Hashtable.cs:972
virtual void Remove(object key)
Removes the element with the specified key from the T:System.Collections.Hashtable.
Definition: Hashtable.cs:1349
bool IsReadOnly
Gets a value indicating whether the T:System.Collections.IDictionary object is read-only.
Definition: IDictionary.cs:48
virtual bool IsReadOnly
Gets a value indicating whether the T:System.Collections.Hashtable is read-only.
Definition: Hashtable.cs:602
Specifies that the class can be serialized.
Enumerates the elements of a nongeneric dictionary.
Provides the abstract base class for a strongly typed collection of key/value pairs.
virtual void Clear()
Removes all elements from the T:System.Collections.Hashtable.
Definition: Hashtable.cs:924
virtual void OnValidate(object key, object value)
Performs additional custom processes when validating the element with the specified key and value.
Defines size, enumerators, and synchronization methods for all nongeneric collections.
Definition: ICollection.cs:8
virtual void OnSetComplete(object key, object oldValue, object newValue)
Performs additional custom processes after setting a value in the T:System.Collections....
Represents a nongeneric collection of key/value pairs.
Definition: IDictionary.cs:8
Supports a simple iteration over a non-generic collection.
Definition: IEnumerator.cs:9
virtual int Count
Gets the number of key/value pairs contained in the T:System.Collections.Hashtable.
Definition: Hashtable.cs:658