DataBindingCollection.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. //
  2. // System.Web.UI.DataBindingCollection.cs
  3. //
  4. // Duncan Mak ([email protected])
  5. //
  6. // (C) Ximian, Inc.
  7. // Copyright (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.Collections;
  29. using System.Security.Permissions;
  30. namespace System.Web.UI {
  31. // CAS - no InheritanceDemand here as the class is sealed
  32. [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
  33. public sealed class DataBindingCollection : ICollection, IEnumerable
  34. {
  35. Hashtable list;
  36. ArrayList removed;
  37. public DataBindingCollection ()
  38. {
  39. list = new Hashtable ();
  40. removed = new ArrayList ();
  41. }
  42. public int Count {
  43. get { return list.Count; }
  44. }
  45. public bool IsReadOnly {
  46. get { return list.IsReadOnly; }
  47. }
  48. public bool IsSynchronized {
  49. get { return list.IsSynchronized; }
  50. }
  51. public DataBinding this [string propertyName] {
  52. get { return list [propertyName] as DataBinding; }
  53. }
  54. public string [] RemovedBindings {
  55. get { return (string []) removed.ToArray (typeof (string)); }
  56. }
  57. public object SyncRoot {
  58. get { return list.SyncRoot; }
  59. }
  60. public void Add (DataBinding binding)
  61. {
  62. list.Add (binding.PropertyName, binding);
  63. RaiseChanged ();
  64. }
  65. public void Clear ()
  66. {
  67. list.Clear ();
  68. }
  69. public void CopyTo (Array array, int index)
  70. {
  71. list.Values.CopyTo (array, index);
  72. }
  73. public IEnumerator GetEnumerator ()
  74. {
  75. return list.GetEnumerator ();
  76. }
  77. public void Remove (DataBinding binding)
  78. {
  79. string key = binding.PropertyName;
  80. Remove (key);
  81. }
  82. public void Remove (string propertyName)
  83. {
  84. removed.Add (propertyName);
  85. list.Remove (propertyName);
  86. RaiseChanged ();
  87. }
  88. public void Remove (string propertyName,
  89. bool addToRemovedList)
  90. {
  91. if (addToRemovedList)
  92. removed.Add (String.Empty); // LAMESPEC
  93. else
  94. removed.Add (propertyName);
  95. list.Remove (propertyName);
  96. }
  97. #if NET_2_0
  98. public bool Contains (string propertyName)
  99. {
  100. return list.Contains (propertyName);
  101. }
  102. public event EventHandler Changed;
  103. public
  104. #else
  105. internal event EventHandler Changed;
  106. internal
  107. #endif
  108. void RaiseChanged ()
  109. {
  110. if (Changed != null)
  111. Changed (this, EventArgs.Empty);
  112. }
  113. }
  114. }