mscorlib(4.0.0.0) API with additions
SettingsPropertyCollection.cs
1 using System.Collections;
2 
3 namespace System.Configuration
4 {
7  {
8  private Hashtable _Hashtable;
9 
10  private bool _ReadOnly;
11 
15  public SettingsProperty this[string name]
16  {
17  get
18  {
19  return _Hashtable[name] as SettingsProperty;
20  }
21  }
22 
25  public int Count => _Hashtable.Count;
26 
30  public bool IsSynchronized => false;
31 
34  public object SyncRoot => this;
35 
38  {
40  }
41 
45  public void Add(SettingsProperty property)
46  {
47  if (_ReadOnly)
48  {
49  throw new NotSupportedException();
50  }
51  OnAdd(property);
52  _Hashtable.Add(property.Name, property);
53  try
54  {
55  OnAddComplete(property);
56  }
57  catch
58  {
59  _Hashtable.Remove(property.Name);
60  throw;
61  }
62  }
63 
67  public void Remove(string name)
68  {
69  if (_ReadOnly)
70  {
71  throw new NotSupportedException();
72  }
73  SettingsProperty settingsProperty = (SettingsProperty)_Hashtable[name];
74  if (settingsProperty != null)
75  {
76  OnRemove(settingsProperty);
77  _Hashtable.Remove(name);
78  try
79  {
80  OnRemoveComplete(settingsProperty);
81  }
82  catch
83  {
84  _Hashtable.Add(name, settingsProperty);
85  throw;
86  }
87  }
88  }
89 
93  {
94  return _Hashtable.Values.GetEnumerator();
95  }
96 
99  public object Clone()
100  {
101  return new SettingsPropertyCollection(_Hashtable);
102  }
103 
105  public void SetReadOnly()
106  {
107  if (!_ReadOnly)
108  {
109  _ReadOnly = true;
110  }
111  }
112 
115  public void Clear()
116  {
117  if (_ReadOnly)
118  {
119  throw new NotSupportedException();
120  }
121  OnClear();
122  _Hashtable.Clear();
123  OnClearComplete();
124  }
125 
128  protected virtual void OnAdd(SettingsProperty property)
129  {
130  }
131 
134  protected virtual void OnAddComplete(SettingsProperty property)
135  {
136  }
137 
139  protected virtual void OnClear()
140  {
141  }
142 
144  protected virtual void OnClearComplete()
145  {
146  }
147 
150  protected virtual void OnRemove(SettingsProperty property)
151  {
152  }
153 
156  protected virtual void OnRemoveComplete(SettingsProperty property)
157  {
158  }
159 
163  public void CopyTo(Array array, int index)
164  {
165  _Hashtable.Values.CopyTo(array, index);
166  }
167 
169  {
170  _Hashtable = (Hashtable)h.Clone();
171  }
172  }
173 }
virtual void OnAddComplete(SettingsProperty property)
Performs additional, custom processing after adding to the contents of 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
Used internally as the class that represents metadata about an individual configuration property.
Definition: __Canon.cs:3
virtual object Clone()
Creates a shallow copy of the T:System.Collections.Hashtable.
Definition: Hashtable.cs:946
Contains a collection of T:System.Configuration.SettingsProperty objects.
object Clone()
Creates a copy of the existing collection.
virtual ICollection Values
Gets an T:System.Collections.ICollection containing the values in the T:System.Collections....
Definition: Hashtable.cs:631
void Remove(string name)
Removes a T:System.Configuration.SettingsProperty object from the collection.
bool IsSynchronized
Gets a value that indicates whether access to the collection is synchronized (thread safe).
virtual void OnAdd(SettingsProperty property)
Performs additional, custom processing when adding to the contents of the T:System....
Exposes an enumerator, which supports a simple iteration over a non-generic collection....
Definition: IEnumerable.cs:9
virtual void OnRemove(SettingsProperty property)
Performs additional, custom processing when removing the contents of the T:System....
void Clear()
Removes all T:System.Configuration.SettingsProperty objects from the collection.
Represents a collection of key/value pairs that are organized based on the hash code of the key....
Definition: Hashtable.cs:17
SettingsPropertyCollection()
Initializes a new instance of the T:System.Configuration.SettingsPropertyCollection class.
Supports cloning, which creates a new instance of a class with the same value as an existing instance...
Definition: ICloneable.cs:7
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition: Array.cs:17
void Add(SettingsProperty property)
Adds a T:System.Configuration.SettingsProperty object to the collection.
virtual void OnClear()
Performs additional, custom processing when clearing the contents of the T:System....
IEnumerator GetEnumerator()
Returns an enumerator that iterates through a collection.
IEnumerator GetEnumerator()
Gets the T:System.Collections.IEnumerator object as it applies to the collection.
virtual void OnRemoveComplete(SettingsProperty property)
Performs additional, custom processing after removing the contents of the T:System....
virtual void OnClearComplete()
Performs additional, custom processing after clearing the contents of the T:System....
virtual void Remove(object key)
Removes the element with the specified key from the T:System.Collections.Hashtable.
Definition: Hashtable.cs:1349
int Count
Gets a value that specifies the number of T:System.Configuration.SettingsProperty objects in the coll...
static StringComparer CurrentCultureIgnoreCase
Gets a T:System.StringComparer object that performs case-insensitive string comparisons using the wor...
virtual void Clear()
Removes all elements from the T:System.Collections.Hashtable.
Definition: Hashtable.cs:924
The exception that is thrown when an invoked method is not supported, or when there is an attempt to ...
Defines size, enumerators, and synchronization methods for all nongeneric collections.
Definition: ICollection.cs:8
void CopyTo(Array array, int index)
Copies the elements of the T:System.Collections.ICollection to an T:System.Array, starting at a parti...
object SyncRoot
Gets the object to synchronize access to the collection.
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
void SetReadOnly()
Sets the collection to be read-only.
Represents a string comparison operation that uses specific case and culture-based or ordinal compari...
void CopyTo(Array array, int index)
Copies this T:System.Configuration.SettingsPropertyCollection object to an array.
virtual string Name
Gets or sets the name of the T:System.Configuration.SettingsProperty.