public StateItem Add(string key, object value) { if (string.IsNullOrEmpty(key)) { throw ExceptionUtil.ParameterNullOrEmpty("key"); } StateItem item = this.bag[key] as StateItem; if (item == null) { if ((value != null) || this.marked) { item = new StateItem(value); this.bag.Add(key, item); } } else if ((value == null) && !this.marked) { this.bag.Remove(key); } else { item.Value = value; } if ((item != null) && this.marked) { item.IsDirty = true; } return item; }
public StateItem Add(string key, object value) { if (string.IsNullOrEmpty(key)) { throw ExceptionUtil.ParameterNullOrEmpty("key"); } StateItem item = this.bag[key] as StateItem; if (item == null) { if ((value != null) || this.marked) { item = new StateItem(value); this.bag.Add(key, item); } } else if ((value == null) && !this.marked) { this.bag.Remove(key); } else { item.Value = value; } if ((item != null) && this.marked) { item.IsDirty = true; } return(item); }
/* * Return object containing state that has been modified since "mark". * Returns null if there is no modified state. */ /// <include file='doc\StateBag.uex' path='docs/doc[@for="StateBag.SaveViewState"]/*' /> /// <devdoc> /// <para>Returns an object that contains all state changes for items stored in the /// <see langword='StateBag'/> object.</para> /// </devdoc> internal object SaveViewState() { ArrayList changedKeys = null; ArrayList changedValues = null; if (bag.Count != 0) { IDictionaryEnumerator e = bag.GetEnumerator(); while (e.MoveNext()) { StateItem item = (StateItem)(e.Value); if (item.IsDirty) { if (changedKeys == null) { changedKeys = new ArrayList(5); changedValues = new ArrayList(5); } changedKeys.Add(e.Key); changedValues.Add(item.Value); } } if (changedKeys != null) { return(new Pair(changedKeys, changedValues)); } } return(null); }
/* * Add a new StateItem or update an existing StateItem in the bag. */ /// <include file='doc\StateBag.uex' path='docs/doc[@for="StateBag.Add"]/*' /> /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public StateItem Add(string key, object value) { if (key == null || key.Length == 0) { throw new ArgumentException(HttpRuntime.FormatResourceString(SR.Key_Cannot_Be_Null)); } StateItem item = bag[key] as StateItem; if (item == null) { if (value != null || marked) { item = new StateItem(value); bag.Add(key, item); } } else { if (value == null && !marked) { bag.Remove(key); } else { item.Value = value; } } if (item != null && marked) { item.IsDirty = true; } return(item); }
/* * Return object containing state that has been modified since "mark". * Returns null if there is no modified state. */ /// <devdoc> /// <para>Returns an object that contains all state changes for items stored in the /// <see langword='StateBag'/> object.</para> /// </devdoc> internal object SaveViewState() { ArrayList data = null; // if (bag.Count != 0) { IDictionaryEnumerator e = bag.GetEnumerator(); while (e.MoveNext()) { StateItem item = (StateItem)(e.Value); if (item.IsDirty) { if (data == null) { data = new ArrayList(); } #if OBJECTSTATEFORMATTER data.Add(new IndexedString((string)e.Key)); #else data.Add(e.Key); #endif data.Add(item.Value); } } } return(data); }
public void SetDirty(bool dirty) { foreach (DictionaryEntry de in ht) { StateItem si = (StateItem)de.Value; si.IsDirty = dirty; } }
public void SetItemDirty(string key, bool dirty) { StateItem si = (StateItem)ht [key]; if (si != null) { si.IsDirty = dirty; } }
/* * Internal method for setting dirty flag on a state item. * Used internallly to prevent state management of certain properties. */ /// <include file='doc\StateBag.uex' path='docs/doc[@for="StateBag.SetItemDirty"]/*' /> /// <internalonly/> /// <devdoc> /// </devdoc> public void SetItemDirty(string key, bool dirty) { StateItem item = bag[key] as StateItem; if (item != null) { item.IsDirty = dirty; } }
/* * Return the dirty flag of the state item. * Returns false if there is not an item for given key. */ /// <include file='doc\StateBag.uex' path='docs/doc[@for="StateBag.IsItemDirty"]/*' /> /// <devdoc> /// <para>Checks an item stored in the <see langword='StateBag'/> to see if it has been /// modified.</para> /// </devdoc> public bool IsItemDirty(string key) { StateItem item = bag[key] as StateItem; if (item != null) { return(item.IsDirty); } return(false); }
public StateItem Add(string key, object value) { StateItem si = ht [key] as StateItem; if (si == null) { ht [key] = si = new StateItem(value); } si.Value = value; si.IsDirty |= track; return(si); }
/* * Get or set value of a StateItem. * A set will automatically add a new StateItem for a * key which is not already in the bag. A set to null * will remove the item if set before mark, otherwise * a null set will be saved to allow tracking of state * removed after mark. */ /// <include file='doc\StateBag.uex' path='docs/doc[@for="StateBag.this"]/*' /> /// <devdoc> /// <para> Indicates the value of an item stored in the /// <see langword='StateBag'/> /// object. Setting this property with a key not already stored in the StateBag will /// add an item to the bag. If you set this property to <see langword='null'/> before /// the TrackState method is called on an item will remove it from the bag. Otherwise, /// when you set this property to <see langword='null'/> /// the key will be saved to allow tracking of the item's state.</para> /// </devdoc> public object this[string key] { get { if (key == null || key.Length == 0) { throw new ArgumentException(HttpRuntime.FormatResourceString(SR.Key_Cannot_Be_Null)); } StateItem item = bag[key] as StateItem; if (item != null) { return(item.Value); } return(null); } set { Add(key, value); } }
/* * Get or set value of a StateItem. * A set will automatically add a new StateItem for a * key which is not already in the bag. A set to null * will remove the item if set before mark, otherwise * a null set will be saved to allow tracking of state * removed after mark. */ /// <devdoc> /// <para> Indicates the value of an item stored in the /// <see langword='StateBag'/> /// object. Setting this property with a key not already stored in the StateBag will /// add an item to the bag. If you set this property to <see langword='null'/> before /// the TrackState method is called on an item will remove it from the bag. Otherwise, /// when you set this property to <see langword='null'/> /// the key will be saved to allow tracking of the item's state.</para> /// </devdoc> public object this[string key] { get { if (String.IsNullOrEmpty(key)) { throw ExceptionUtil.ParameterNullOrEmpty("key"); } StateItem item = bag[key] as StateItem; if (item != null) { return(item.Value); } return(null); } set { Add(key, value); } }
internal object SaveViewState() { Hashtable h = null; foreach (DictionaryEntry de in ht) { StateItem si = (StateItem)de.Value; if (si.IsDirty) { if (h == null) { h = new Hashtable(); } h.Add(de.Key, si.Value); } } return(h); }
public void AddAttributes(HtmlTextWriter writer) { if (this._bag.Count > 0) { IDictionaryEnumerator enumerator = this._bag.GetEnumerator(); while (enumerator.MoveNext()) { StateItem item = enumerator.Value as StateItem; if (item != null) { string str = item.Value as string; string key = enumerator.Key as string; if ((key != null) && (str != null)) { writer.AddAttribute(key, str, true); } } } } }
public object this [string key] { get { StateItem i = ht [key] as StateItem; if (i != null) { return(i.Value); } return(null); } set { if (value == null && !IsTrackingViewState) { Remove(key); } else { Add(key, value); } } }
/// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public void AddAttributes(HtmlTextWriter writer) { if (_bag.Count > 0) { IDictionaryEnumerator e = _bag.GetEnumerator(); while (e.MoveNext()) { StateItem item = e.Value as StateItem; if (item != null) { string value = item.Value as string; string key = e.Key as string; if (key != null && value != null) { writer.AddAttribute(key, value, true /*fEncode*/); } } } } }
internal object SaveViewState() { ArrayList list = null; if (this.bag.Count != 0) { IDictionaryEnumerator enumerator = this.bag.GetEnumerator(); while (enumerator.MoveNext()) { StateItem item = (StateItem)enumerator.Value; if (item.IsDirty) { if (list == null) { list = new ArrayList(); } list.Add(new IndexedString((string)enumerator.Key)); list.Add(item.Value); } } } return(list); }
/* * Add a new StateItem or update an existing StateItem in the bag. */ /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public StateItem Add(string key,object value) { if (String.IsNullOrEmpty(key)) throw ExceptionUtil.ParameterNullOrEmpty("key"); StateItem item = bag[key] as StateItem; if (item == null) { if (value != null || marked) { item = new StateItem(value); bag.Add(key,item); } } else { if (value == null && !marked) { bag.Remove(key); } else { item.Value = value; } } if (item != null && marked) { item.IsDirty = true; } return item; }
public StateItem Add (string key, object value) { if (key == null || key.Length == 0) throw new ArgumentException (HttpRuntime.FormatResourceString ("Key_Cannot_Be_Null")); StateItem val = bag [key] as StateItem; //don't throw exception when null if(val == null) { if(value != null || marked) { val = new StateItem (value); bag.Add (key, val); } } else if (value == null && !marked) bag.Remove (key); else val.Value = value; if (val != null && marked) { val.IsDirty = true; } return val; }
public void FixtureSetup () { item = new StateBag ().Add ("key", "value"); }
public bool IsItemDirty(string key) { StateItem si = ht [key] as StateItem; return(si != null && si.IsDirty); }
public bool IsItemDirty(string key) { StateItem item = this.bag[key] as StateItem; return((item != null) && item.IsDirty); }
public string ToString(string preserve, string removeList, System.Web.UI.StateBag viewState) { HttpRequest Request = HttpContext.Current.Request; HttpServerUtility Server = HttpContext.Current.Server; string[] List; if (removeList == "") { List = new string[1]; } else { List = removeList.Split(new Char[] { ';' }); } if (preserve == "All" || preserve == "GET") { if (viewState != null) { int length = viewState.Count; string[] keys = new string[length]; System.Web.UI.StateItem[] values = new System.Web.UI.StateItem[length]; viewState.Keys.CopyTo(keys, 0); viewState.Values.CopyTo(values, 0); string cvalue = ""; for (int i = 0; i < length; i++) { if (values[i].Value != null) { cvalue = values[i].Value.ToString(); } else { cvalue = ""; } string ckey = ""; if (keys[i].EndsWith("SortField") && cvalue != "Default") { ckey = keys[i].Replace("SortField", "Order"); } if (keys[i].EndsWith("SortDir")) { ckey = keys[i].Replace("SortDir", "Dir"); } if (keys[i].EndsWith("PageNumber") && cvalue != "1") { ckey = keys[i].Replace("PageNumber", "Page"); } if (ckey != "" && Array.IndexOf(List, ckey) < 0) { if (this[ckey] == null) { Add(ckey, cvalue); } else { this[ckey] = cvalue; } } } } for (int i = 0; i < Request.QueryString.Count; i++) { if (Array.IndexOf(List, Request.QueryString.AllKeys[i]) < 0 && BaseGet(Request.QueryString.AllKeys[i]) == null) { foreach (string val in Request.QueryString.GetValues(i)) { Add(Request.QueryString.AllKeys[i], Server.UrlEncode(val)); } } } } if (preserve == "All" || preserve == "POST") { for (int i = 0; i < Request.Form.Count; i++) { if (Array.IndexOf(List, Request.Form.AllKeys[i]) < 0 && Request.Form.AllKeys[i] != "__EVENTTARGET" && Request.Form.AllKeys[i] != "__EVENTARGUMENT" && Request.Form.AllKeys[i] != "__VIEWSTATE" && BaseGet(Request.Form.AllKeys[i]) == null) { foreach (string val in Request.Form.GetValues(i)) { Add(Request.Form.AllKeys[i], Server.UrlEncode(val)); } } } } return(ToString("")); }
public StateItem Add (string key, object value) { StateItem si = ht [key] as StateItem; if (si == null) ht [key] = si = new StateItem (value); si.Value = value; si.IsDirty |= track; return si; }