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;
35 namespace System.Web.UI.WebControls
38 public class ParameterCollection : StateManagedCollection
41 private static Type[] _knownTypes = new Type[] {
42 typeof (ControlParameter),
43 typeof (CookieParameter),
44 typeof (FormParameter),
46 typeof (QueryStringParameter),
47 typeof (SessionParameter) };
49 private EventHandler _parametersChanged;
50 private KeyedList _values;
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 ();
75 return new CookieParameter ();
78 return new FormParameter ();
81 return new Parameter ();
84 return new QueryStringParameter ();
87 return new SessionParameter ();
91 throw new ArgumentOutOfRangeException ("index");
94 protected override Type[] GetKnownTypes ()
99 public IOrderedDictionary GetValues (Control control)
103 _values = new KeyedList ();
104 foreach (Parameter param in this)
106 string name = param.Name;
107 for (int i = 1; _values.Contains (name); i++)
109 name = param.Name + i.ToString ();
111 _values.Add (name, param.ParameterValue);
117 public void Insert (int idx, Parameter param)
119 ((IList)this).Insert (idx, param);
122 protected override void OnClearComplete ()
124 base.OnClearComplete ();
125 OnParametersChanged (EventArgs.Empty);
128 protected override void OnInsert (int idx, object value)
130 base.OnInsert (idx, value);
131 ((Parameter)value).SetOwnerCollection (this);
134 protected override void OnInsertComplete (int idx, object value)
136 base.OnInsertComplete (idx, value);
137 OnParametersChanged (EventArgs.Empty);
140 protected virtual void OnParametersChanged (EventArgs e)
142 if (_parametersChanged != null)
143 _parametersChanged(this, e);
148 protected override void OnValidate (object o)
152 if ((o is Parameter) == false)
153 throw new ArgumentException ("o is not a Parameter");
156 public void Remove (Parameter param)
158 ((IList)this).Remove (param);
161 public void RemoveAt (int idx)
163 ((IList)this).RemoveAt (idx);
167 protected override void SetDirtyObject (object o)
169 throw new NotImplementedException ();
172 internal void CallOnParameterChanged ()
174 OnParametersChanged (EventArgs.Empty);
177 private int IndexOfString (string name)
179 for (int i = 0; i < Count; i++)
181 if (((Parameter)((IList)this)[i]).Name == name)
187 public Parameter this[int idx] {
189 return (Parameter) ((IList)this)[idx];
192 ((IList)this)[idx] = value;
196 public Parameter this[string name] {
198 int idx = IndexOfString (name);
201 return ((Parameter) ((IList)this)[idx]);
204 int idx = IndexOfString (name);
209 ((IList)this)[idx] = value;
213 public event EventHandler ParametersChanged {
214 add { _parametersChanged += value; }
215 remove { _parametersChanged -= value; }