ExpressionBindingCollection.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. //
  2. // System.Web.UI.ExpressionBindingCollection.cs
  3. //
  4. // Authors:
  5. // Sanjay Gupta [email protected])
  6. //
  7. // (C) 2004 Novell, Inc. (http://www.novell.com)
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. #if NET_2_0
  30. using System;
  31. using System.Collections;
  32. namespace System.Web.UI {
  33. public sealed class ExpressionBindingCollection : ICollection, IEnumerable
  34. {
  35. Hashtable list;
  36. ArrayList removed;
  37. public ExpressionBindingCollection ()
  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 ExpressionBinding this [string propertyName] {
  52. get { return list [propertyName] as ExpressionBinding; }
  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 (ExpressionBinding binding)
  61. {
  62. list.Add (binding.PropertyName, binding);
  63. OnChanged (new EventArgs ());
  64. }
  65. public void Clear ()
  66. {
  67. list.Clear ();
  68. removed.Clear ();
  69. OnChanged (new EventArgs ());
  70. }
  71. public bool Contains (string propertyName)
  72. {
  73. return list.Contains (propertyName);
  74. }
  75. public void CopyTo (Array array, int index)
  76. {
  77. list.CopyTo (array, index);
  78. }
  79. public void CopyTo (ExpressionBinding [] bindings, int index)
  80. {
  81. if (index < 0)
  82. throw new ArgumentNullException ("Index cannot be negative");
  83. if (index >= bindings.Length)
  84. throw new ArgumentException ("Index cannot be greater than or equal to length of array passed");
  85. if (list.Count > (bindings.Length - index + 1))
  86. throw new ArgumentException ("Number of elements in source is greater than available space from index to end of destination");
  87. foreach (string key in list.Keys)
  88. bindings [index++] = (ExpressionBinding) list [key];
  89. }
  90. public IEnumerator GetEnumerator ()
  91. {
  92. return list.GetEnumerator ();
  93. }
  94. public void Remove (ExpressionBinding binding)
  95. {
  96. Remove(binding.PropertyName, true);
  97. }
  98. public void Remove (string propertyName)
  99. {
  100. Remove (propertyName, true);
  101. }
  102. public void Remove (string propertyName, bool addToRemovedList)
  103. {
  104. if (addToRemovedList)
  105. removed.Add (String.Empty);
  106. else
  107. removed.Add (propertyName);
  108. list.Remove (propertyName);
  109. OnChanged (new EventArgs ());
  110. }
  111. public event EventHandler Changed;
  112. protected void OnChanged (EventArgs e)
  113. {
  114. if (Changed != null)
  115. Changed (this, e);
  116. }
  117. }
  118. }
  119. #endif