ControlCollection.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. //
  2. // System.Web.UI.ControlCollection.cs
  3. //
  4. // Duncan Mak ([email protected])
  5. //
  6. // (C) Ximian, Inc.
  7. //
  8. using System;
  9. using System.Collections;
  10. namespace System.Web.UI {
  11. public class ControlCollection : ICollection, IEnumerable
  12. {
  13. ArrayList list = new ArrayList ();
  14. Control owner;
  15. public ControlCollection (Control owner)
  16. {
  17. if (owner == null)
  18. throw new ArgumentException ();
  19. this.owner = owner;
  20. }
  21. public int Count {
  22. get { return list.Count; }
  23. }
  24. public bool IsReadOnly {
  25. get { return list.IsReadOnly; }
  26. }
  27. public bool IsSynchronized {
  28. get { return list.IsSynchronized; }
  29. }
  30. public virtual Control this [int index] {
  31. get { return list [index] as Control; }
  32. }
  33. protected Control Owner {
  34. get { return owner; }
  35. }
  36. public object SyncRoot {
  37. get { return list.SyncRoot; }
  38. }
  39. public virtual void Add (Control child)
  40. {
  41. if (child == null)
  42. throw new ArgumentNullException ();
  43. if (IsReadOnly)
  44. throw new HttpException ();
  45. list.Add (child);
  46. }
  47. public virtual void AddAt (int index, Control child)
  48. {
  49. if (child == null) // maybe we should check for ! (child is Control)?
  50. throw new ArgumentNullException ();
  51. if ((index < 0) || (index > Count))
  52. throw new ArgumentOutOfRangeException ();
  53. if (IsReadOnly)
  54. throw new HttpException ();
  55. list [index] = child;
  56. }
  57. public virtual void Clear ()
  58. {
  59. list.Clear ();
  60. }
  61. public virtual bool Contains (Control c)
  62. {
  63. return list.Contains (c as object);
  64. }
  65. public void CopyTo (Array array, int index)
  66. {
  67. list.CopyTo (array, index);
  68. }
  69. public IEnumerator GetEnumerator ()
  70. {
  71. return list.GetEnumerator ();
  72. }
  73. public virtual int IndexOf (Control c)
  74. {
  75. return list.IndexOf (c as object);
  76. }
  77. public virtual void Remove (Control value)
  78. {
  79. list.Remove (value as object);
  80. }
  81. public virtual void RemoveAt (int index)
  82. {
  83. if (IsReadOnly)
  84. throw new HttpException ();
  85. list.RemoveAt (index);
  86. }
  87. }
  88. }