BaseControlCollection.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Specialized;
  4. using System.Runtime.Serialization;
  5. namespace MonoTests.SystemWeb.Framework
  6. {
  7. /// <summary>
  8. /// The collection of <see cref="BaseControl"/> instances used by <see cref="FormRequest"/>.
  9. /// </summary>
  10. /// <seealso cref="BaseControl"/>
  11. /// <seealso cref="FormRequest"/>
  12. [Serializable]
  13. public sealed class BaseControlCollection : NameObjectCollectionBase
  14. {
  15. /// <summary>
  16. /// The default constructor. Does nothing.
  17. /// </summary>
  18. public BaseControlCollection ()
  19. {
  20. }
  21. /// <summary>
  22. /// The constructor is necessary because this class overrides
  23. /// <see cref="System.Collections.Specialized.NameObjectCollectionBase"/>
  24. /// which makes a custom serialization.
  25. /// </summary>
  26. /// <param name="info">Serialization info.</param>
  27. /// <param name="context">Serialization context.</param>
  28. /// <seealso cref="System.Collections.Specialized.NameObjectCollectionBase"/>
  29. public BaseControlCollection (SerializationInfo info, StreamingContext context)
  30. : base (info, context)
  31. {
  32. }
  33. /// <summary>
  34. /// Sets or gets the control with the given name. Get is guaranteed
  35. /// to return not null value
  36. /// </summary>
  37. public BaseControl this [string name]
  38. {
  39. get {return base.BaseGet (name) as BaseControl;}
  40. set {base.BaseSet (name, value);}
  41. }
  42. /// <summary>
  43. /// Remove a control from the collection.
  44. /// </summary>
  45. /// <param name="name">The name of the control to remove.</param>
  46. public void Remove (string name)
  47. {
  48. base.BaseRemove (name);
  49. }
  50. /// <summary>
  51. /// Add a new control to the collection. If there is control with
  52. /// the same name, it will be kept intact.
  53. /// </summary>
  54. /// <param name="name">The name of a control to be added.</param>
  55. public void Add (string name)
  56. {
  57. BaseControl bc = this[name];
  58. if (bc != null)
  59. return;
  60. bc = new BaseControl ();
  61. bc.Name = name;
  62. base.BaseAdd (name, bc);
  63. }
  64. /// <summary>
  65. /// Add a new control to the collection. If there is control with
  66. /// the same name, it will be overwritten.
  67. /// </summary>
  68. /// <param name="control">New control.</param>
  69. public void Add (BaseControl control)
  70. {
  71. this [control.Name] = control;
  72. }
  73. }
  74. }