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;
37 namespace System.Web.UI.WebControls
40 [EditorAttribute ("System.Web.UI.Design.WebControls.ParameterCollectionEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
41 public class ParameterCollection : StateManagedCollection
44 static Type[] _knownTypes = new Type[] {
45 typeof (ControlParameter),
46 typeof (CookieParameter),
47 typeof (FormParameter),
49 typeof (QueryStringParameter),
50 typeof (SessionParameter) };
52 EventHandler _parametersChanged;
54 public int Add (Parameter param)
56 return ((IList)this).Add (param);
59 public int Add (string name, string value)
61 return ((IList)this).Add (new Parameter (name, TypeCode.Object, value));
64 public int Add (string name, TypeCode type, string value)
66 return ((IList)this).Add (new Parameter (name, type, value));
69 public int Add (string name, DbType dbType, string value)
71 return ((IList)this).Add (new Parameter (name, dbType, value));
74 protected override object CreateKnownType (int idx)
78 return new ControlParameter ();
80 return new CookieParameter ();
82 return new FormParameter ();
84 return new Parameter ();
86 return new QueryStringParameter ();
88 return new SessionParameter ();
91 throw new ArgumentOutOfRangeException ("index");
94 protected override Type[] GetKnownTypes ()
99 public IOrderedDictionary GetValues (HttpContext context, Control control)
101 OrderedDictionary values = new OrderedDictionary ();
102 foreach (Parameter param in this)
104 string name = param.Name;
105 for (int i = 1; values.Contains (name); i++)
106 name = param.Name + i.ToString ();
107 values.Add (name, param.GetValue (context, control));
112 public void UpdateValues (HttpContext context, Control control)
114 foreach (Parameter param in this)
115 param.UpdateValue (context, control);
118 public void Insert (int idx, Parameter param)
120 ((IList)this).Insert (idx, param);
123 protected override void OnClearComplete ()
125 base.OnClearComplete ();
126 OnParametersChanged (EventArgs.Empty);
129 protected override void OnInsert (int idx, object value)
131 base.OnInsert (idx, value);
132 ((Parameter)value).SetOwnerCollection (this);
135 protected override void OnInsertComplete (int idx, object value)
137 base.OnInsertComplete (idx, value);
138 OnParametersChanged (EventArgs.Empty);
141 protected virtual void OnParametersChanged (EventArgs e)
143 if (_parametersChanged != null)
144 _parametersChanged(this, e);
147 protected override void OnValidate (object o)
151 if ((o is Parameter) == false)
152 throw new ArgumentException ("o is not a Parameter");
155 public void Remove (Parameter param)
157 ((IList)this).Remove (param);
160 public void RemoveAt (int idx)
162 ((IList)this).RemoveAt (idx);
165 protected override void SetDirtyObject (object o)
167 ((Parameter)o).SetDirty ();
170 internal void CallOnParameterChanged ()
172 OnParametersChanged (EventArgs.Empty);
175 int IndexOfString (string name)
177 for (int i = 0; i < Count; i++)
179 if (string.Compare (((Parameter) ((IList) this) [i]).Name, name, StringComparison.OrdinalIgnoreCase) == 0)
185 public Parameter this[int idx] {
187 return (Parameter) ((IList)this)[idx];
190 ((IList)this)[idx] = value;
194 public Parameter this[string name] {
196 int idx = IndexOfString (name);
199 return ((Parameter) ((IList)this)[idx]);
202 int idx = IndexOfString (name);
207 ((IList)this)[idx] = value;
211 public event EventHandler ParametersChanged {
212 add { _parametersChanged += value; }
213 remove { _parametersChanged -= value; }
216 public bool Contains (Parameter param)
218 return ((IList)this).Contains (param);
221 public void CopyTo (Parameter[] paramArray, int index)
223 ((IList)this).CopyTo (paramArray, index);
226 public int IndexOf (Parameter param)
228 return ((IList)this).IndexOf (param);
231 protected override void OnRemoveComplete (int index, object value)
233 base.OnRemoveComplete (index, value);
234 OnParametersChanged (EventArgs.Empty);