3 using System.Collections;
6 public sealed class HttpStaticObjectsCollection : ICollection, IEnumerable {
7 private Hashtable _Objects;
9 // Needs to hold object items that can be latebound and can be serialized
10 public HttpStaticObjectsCollection ()
12 _Objects = new Hashtable();
15 public object GetObject (string name)
20 public IEnumerator GetEnumerator ()
22 return _Objects.GetEnumerator ();
25 public void CopyTo (Array array, int index)
27 _Objects.CopyTo (array, index);
30 internal IDictionary GetObjects ()
35 public object this [string name] {
36 get { return _Objects [name]; }
40 get { return _Objects.Count; }
43 public bool IsReadOnly {
47 public bool IsSynchronized {
51 public object SyncRoot {
56 private void Set (string name, object obj)
58 _Objects [name] = obj;
61 internal void Serialize (BinaryWriter w)
65 foreach (string key in _Objects.Keys) {
67 object value = _Objects [key];
69 w.Write (System.Web.Util.AltSerialization.NullIndex);
73 System.Web.Util.AltSerialization.SerializeByType (w, value);
78 internal static HttpStaticObjectsCollection Deserialize (BinaryReader r)
80 HttpStaticObjectsCollection result = new HttpStaticObjectsCollection ();
81 for (int i = r.ReadInt32 (); i > 0; i--) {
82 string key = r.ReadString ();
83 int index = r.ReadInt32 ();
84 if (index == System.Web.Util.AltSerialization.NullIndex)
85 result.Set (key, null);
87 result.Set (key, System.Web.Util.AltSerialization.DeserializeFromIndex (index, r));
93 internal byte [] ToByteArray ()
95 MemoryStream stream = null;
97 stream = new MemoryStream ();
98 Serialize (new BinaryWriter (stream));
99 return stream.GetBuffer ();
108 internal static HttpStaticObjectsCollection FromByteArray (byte [] data)
110 HttpStaticObjectsCollection objs = null;
111 MemoryStream stream = null;
113 stream = new MemoryStream (data);
114 objs = Deserialize (new BinaryReader (stream));