3 using System.Collections;
\r
5 namespace System.Web {
\r
6 public sealed class HttpStaticObjectsCollection : ICollection, IEnumerable {
\r
7 private Hashtable _Objects;
\r
9 // Needs to hold object items that can be latebound and can be serialized
\r
10 public HttpStaticObjectsCollection() {
\r
11 _Objects = new Hashtable();
\r
14 public object GetObject(string name) {
\r
18 public IEnumerator GetEnumerator() {
\r
19 return _Objects.GetEnumerator ();
\r
22 public void CopyTo(Array array, int index) {
\r
23 _Objects.CopyTo (array, index);
\r
26 internal IDictionary GetObjects() {
\r
30 public object this[string name] {
\r
32 return _Objects [name];
\r
38 return _Objects.Count;
\r
42 public bool IsReadOnly {
\r
48 public bool IsSynchronized {
\r
54 public object SyncRoot {
\r
60 private void Set (string name, object obj)
\r
62 _Objects [name] = obj;
\r
65 internal void Serialize (BinaryWriter w)
\r
69 foreach (string key in _Objects.Keys) {
\r
71 object value = _Objects [key];
\r
72 if (value == null) {
\r
73 w.Write (System.Web.Util.AltSerialization.NullIndex);
\r
77 System.Web.Util.AltSerialization.SerializeByType (w, value);
\r
82 internal static HttpStaticObjectsCollection Deserialize (BinaryReader r)
\r
84 HttpStaticObjectsCollection result = new HttpStaticObjectsCollection ();
\r
85 for (int i = r.ReadInt32 (); i > 0; i--) {
\r
86 string key = r.ReadString ();
\r
87 int index = r.ReadInt32 ();
\r
88 if (index == System.Web.Util.AltSerialization.NullIndex)
\r
89 result.Set (key, null);
\r
91 result.Set (key, System.Web.Util.AltSerialization.DeserializeFromIndex (index, r));
\r
97 internal byte [] ToByteArray ()
\r
99 MemoryStream stream = null;
\r
101 stream = new MemoryStream ();
\r
102 Serialize (new BinaryWriter (stream));
\r
103 return stream.GetBuffer ();
\r
107 if (stream != null)
\r
112 internal static HttpStaticObjectsCollection FromByteArray (byte [] data)
\r
114 HttpStaticObjectsCollection objs = null;
\r
115 MemoryStream stream = null;
\r
117 stream = new MemoryStream (data);
\r
118 objs = Deserialize (new BinaryReader (stream));
\r
122 if (stream != null)
\r