SettingsPropertyCollection.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. //
  2. // System.Web.UI.WebControls.SettingsPropertyCollection.cs
  3. //
  4. // Authors:
  5. // Chris Toshok ([email protected])
  6. //
  7. // (C) 2005 Novell, Inc (http://www.novell.com)
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using System;
  29. using System.Collections;
  30. namespace System.Configuration
  31. {
  32. public class SettingsPropertyCollection : ICloneable, ICollection, IEnumerable
  33. {
  34. Hashtable items;
  35. bool isReadOnly;
  36. public SettingsPropertyCollection ()
  37. {
  38. items = new Hashtable();
  39. }
  40. public void Add (SettingsProperty property)
  41. {
  42. if (isReadOnly)
  43. throw new NotSupportedException ();
  44. OnAdd (property);
  45. /* actually do the add */
  46. items.Add (property.Name, property);
  47. OnAddComplete (property);
  48. }
  49. public void Clear ()
  50. {
  51. if (isReadOnly)
  52. throw new NotSupportedException ();
  53. OnClear ();
  54. /* actually do the clear */
  55. items.Clear ();
  56. OnClearComplete();
  57. }
  58. public object Clone ()
  59. {
  60. SettingsPropertyCollection col = new SettingsPropertyCollection ();
  61. col.items = (Hashtable)items.Clone ();
  62. return col;
  63. }
  64. public void CopyTo (Array array, int index)
  65. {
  66. items.Values.CopyTo (array, index);
  67. }
  68. public IEnumerator GetEnumerator ()
  69. {
  70. return items.Values.GetEnumerator();
  71. }
  72. public void Remove (string name)
  73. {
  74. if (isReadOnly)
  75. throw new NotSupportedException ();
  76. SettingsProperty property = (SettingsProperty)items[name];
  77. OnRemove (property);
  78. /* actually do the remove */
  79. items.Remove (name);
  80. OnRemoveComplete (property);
  81. }
  82. public void SetReadOnly ()
  83. {
  84. isReadOnly = true;
  85. }
  86. protected virtual void OnAdd (SettingsProperty property)
  87. {
  88. }
  89. protected virtual void OnAddComplete (SettingsProperty property)
  90. {
  91. }
  92. protected virtual void OnClear ()
  93. {
  94. }
  95. protected virtual void OnClearComplete ()
  96. {
  97. }
  98. protected virtual void OnRemove (SettingsProperty property)
  99. {
  100. }
  101. protected virtual void OnRemoveComplete (SettingsProperty property)
  102. {
  103. }
  104. public int Count {
  105. get {
  106. return items.Count;
  107. }
  108. }
  109. public bool IsSynchronized {
  110. get { return false; }
  111. }
  112. public SettingsProperty this [ string name ] {
  113. get {
  114. return (SettingsProperty)items [name];
  115. }
  116. }
  117. public object SyncRoot {
  118. get { return this; }
  119. }
  120. }
  121. }