2 // System.Web.SessionState.SessionDictionary
5 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 // (C) 2002,2003 Ximian, Inc (http://www.ximian.com)
8 // Copyright (C) 2006 Novell, Inc (http://www.novell.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Collections;
32 using System.Collections.Specialized;
34 namespace System.Web.SessionState {
36 internal class SessionDictionary : NameObjectCollectionBase
38 object this_lock = new object ();
40 public SessionDictionary ()
44 internal SessionDictionary Clone ()
46 SessionDictionary sess = new SessionDictionary ();
48 for (int i = 0; i < last; i++) {
49 string key = GetKey (i);
50 sess [key] = this [key];
56 internal void Clear ()
62 internal string GetKey (int index)
66 value = BaseGetKey (index);
71 internal void Remove (string s)
77 internal void RemoveAt (int index)
83 internal void Serialize (BinaryWriter writer)
86 foreach (string key in base.Keys) {
88 System.Web.Util.AltSerialization.Serialize (writer, BaseGet (key));
92 internal static SessionDictionary Deserialize (BinaryReader r)
94 SessionDictionary result = new SessionDictionary ();
95 for (int i = r.ReadInt32(); i > 0; i--)
96 result [r.ReadString ()] =
97 System.Web.Util.AltSerialization.Deserialize (r);
102 internal object this [string s]
115 object obj = BaseGet(s);
116 if ((obj == null) && (value == null))
123 public object this [int index]
135 object obj = BaseGet(index);
136 if ((obj == null) && (value == null))
138 BaseSet (index, value);
143 internal byte [] ToByteArray ()
145 MemoryStream stream = null;
147 stream = new MemoryStream ();
148 Serialize (new BinaryWriter (stream));
149 return stream.GetBuffer ();
158 internal static SessionDictionary FromByteArray (byte [] data)
160 SessionDictionary result = null;
161 MemoryStream stream = null;
163 stream = new MemoryStream (data);
164 result = Deserialize (new BinaryReader (stream));