2 // System.Web.UI.WebControls/ParameterCollection.cs
4 // Author: Todd Berman <tberman@gentoo.org>
6 // (C) 2003 Todd Berman
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
32 using System.Collections;
33 using System.Collections.Specialized;
34 using System.ComponentModel;
36 namespace System.Web.UI.WebControls
39 [EditorAttribute ("System.Web.UI.Design.WebControls.ParameterCollectionEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
40 public class ParameterCollection : StateManagedCollection
43 private static Type[] _knownTypes = new Type[] {
44 typeof (ControlParameter),
45 typeof (CookieParameter),
46 typeof (FormParameter),
48 typeof (QueryStringParameter),
49 typeof (SessionParameter) };
51 private EventHandler _parametersChanged;
53 public int Add (Parameter param)
55 return ((IList)this).Add (param);
58 public int Add (string name, string value)
60 return ((IList)this).Add (new Parameter (name, TypeCode.Object, value));
63 public int Add (string name, TypeCode type, string value)
65 return ((IList)this).Add (new Parameter (name, type, value));
68 protected override object CreateKnownType (int idx)
72 return new ControlParameter ();
74 return new CookieParameter ();
76 return new FormParameter ();
78 return new Parameter ();
80 return new QueryStringParameter ();
82 return new SessionParameter ();
85 throw new ArgumentOutOfRangeException ("index");
88 protected override Type[] GetKnownTypes ()
93 public IOrderedDictionary GetValues (HttpContext context, Control control)
95 OrderedDictionary values = new OrderedDictionary ();
96 foreach (Parameter param in this)
98 string name = param.Name;
99 for (int i = 1; values.Contains (name); i++)
100 name = param.Name + i.ToString ();
101 values.Add (name, param.GetValue (context, control));
106 public void UpdateValues (HttpContext context, Control control)
108 foreach (Parameter param in this)
109 param.UpdateValue (context, control);
112 public void Insert (int idx, Parameter param)
114 ((IList)this).Insert (idx, param);
117 protected override void OnClearComplete ()
119 base.OnClearComplete ();
120 OnParametersChanged (EventArgs.Empty);
123 protected override void OnInsert (int idx, object value)
125 base.OnInsert (idx, value);
126 ((Parameter)value).SetOwnerCollection (this);
129 protected override void OnInsertComplete (int idx, object value)
131 base.OnInsertComplete (idx, value);
132 OnParametersChanged (EventArgs.Empty);
135 protected virtual void OnParametersChanged (EventArgs e)
137 if (_parametersChanged != null)
138 _parametersChanged(this, e);
141 protected override void OnValidate (object o)
145 if ((o is Parameter) == false)
146 throw new ArgumentException ("o is not a Parameter");
149 public void Remove (Parameter param)
151 ((IList)this).Remove (param);
154 public void RemoveAt (int idx)
156 ((IList)this).RemoveAt (idx);
159 protected override void SetDirtyObject (object o)
161 ((Parameter)o).SetDirty ();
164 internal void CallOnParameterChanged ()
166 OnParametersChanged (EventArgs.Empty);
169 private int IndexOfString (string name)
171 for (int i = 0; i < Count; i++)
173 if (string.Compare (((Parameter) ((IList) this) [i]).Name, name, StringComparison.OrdinalIgnoreCase) == 0)
179 public Parameter this[int idx] {
181 return (Parameter) ((IList)this)[idx];
184 ((IList)this)[idx] = value;
188 public Parameter this[string name] {
190 int idx = IndexOfString (name);
193 return ((Parameter) ((IList)this)[idx]);
196 int idx = IndexOfString (name);
201 ((IList)this)[idx] = value;
205 public event EventHandler ParametersChanged {
206 add { _parametersChanged += value; }
207 remove { _parametersChanged -= value; }
210 public bool Contains (Parameter param)
212 return ((IList)this).Contains (param);
215 public void CopyTo (Parameter[] paramArray, int index)
217 ((IList)this).CopyTo (paramArray, index);
220 public int IndexOf (Parameter param)
222 return ((IList)this).IndexOf (param);
225 protected override void OnRemoveComplete (int index, object value)
227 base.OnRemoveComplete (index, value);
228 OnParametersChanged (EventArgs.Empty);