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