2 // System.Web.UI.WebControls.Parameter
5 // Ben Maurer (bmaurer@users.sourceforge.net)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Collections;
33 using System.Collections.Specialized;
37 namespace System.Web.UI.WebControls {
38 public class Parameter : ICloneable, IStateManager {
40 public Parameter () : base ()
44 protected Parameter (Parameter original)
46 this.DefaultValue = original.DefaultValue;
47 this.Direction = original.Direction;
48 this.TreatEmptyStringAsNull = original.TreatEmptyStringAsNull;
49 this.Type = original.Type;
50 this.Name = original.Name;
53 public Parameter (string name)
58 public Parameter(string name, TypeCode type) : this (name)
63 public Parameter (string name, TypeCode type, string defaultValue) : this (name, type)
65 this.DefaultValue = defaultValue;
68 protected virtual Parameter Clone ()
70 return new Parameter (this);
73 protected virtual object Evaluate (Control control)
75 return this.DefaultValue;
78 protected void OnParameterChanged ()
81 _owner.CallOnParameterChanged ();
84 protected virtual void LoadViewState (object savedState)
86 if (savedState == null)
89 ViewState.LoadViewState (savedState);
92 protected virtual object SaveViewState ()
94 if (viewState == null)
96 return viewState.SaveViewState ();
99 protected virtual void TrackViewState ()
101 isTrackingViewState = true;
102 if (viewState != null)
103 viewState.TrackViewState ();
106 object ICloneable.Clone ()
108 return this.Clone ();
111 void IStateManager.LoadViewState (object savedState)
113 this.LoadViewState (savedState);
116 object IStateManager.SaveViewState ()
118 return this.SaveViewState ();
121 void IStateManager.TrackViewState ()
123 this.TrackViewState ();
126 bool IStateManager.IsTrackingViewState {
127 get { return this.IsTrackingViewState; }
131 public override string ToString ()
133 return base.ToString ();
136 public string DefaultValue {
138 return ViewState ["DefaultValue"] as string;
142 if (DefaultValue != value) {
143 ViewState ["DefaultValue"] = value;
144 OnParameterChanged ();
149 public ParameterDirection Direction {
151 object o = ViewState ["Direction"];
153 return (ParameterDirection) o;
155 return ParameterDirection.Input;
159 if (Direction != value) {
160 ViewState ["Direction"] = value;
161 OnParameterChanged ();
169 string s = ViewState ["Name"] as string;
178 ViewState ["Name"] = value;
179 OnParameterChanged ();
184 public bool TreatEmptyStringAsNull {
186 object o = ViewState ["TreatEmptyStringAsNull"];
194 if (TreatEmptyStringAsNull != value) {
195 ViewState ["TreatEmptyStringAsNull"] = value;
196 OnParameterChanged ();
201 public TypeCode Type {
203 object o = ViewState ["Type"];
207 return TypeCode.Object;
212 ViewState ["Type"] = value;
213 OnParameterChanged ();
220 protected StateBag ViewState {
222 if (viewState == null) {
223 viewState = new StateBag ();
224 if (IsTrackingViewState)
225 viewState.TrackViewState ();
231 bool isTrackingViewState = false;
232 protected bool IsTrackingViewState {
233 get { return isTrackingViewState; }
236 private ParameterCollection _owner;
238 internal void SetOwnerCollection (ParameterCollection own)
243 internal object ParameterValue {
245 object param = ViewState["ParameterValue"];
246 //FIXME: need to do some null string checking magic with TreatEmptyStringAsNull here
249 param = DefaultValue;
255 return Convert.ChangeType (param, Type);