2 // System.Net.CookieCollection
\r
5 // Lawrence Pit (loz@cable.a2000.nl)
\r
9 using System.Collections;
\r
10 using System.Runtime.Serialization;
\r
12 namespace System.Net
\r
15 public class CookieCollection : ICollection, IEnumerable
\r
17 private ArrayList list = new ArrayList ();
\r
20 public CookieCollection ()
\r
27 get { return list.Count; }
\r
30 public bool IsSynchronized {
\r
31 get { return false; }
\r
34 public Object SyncRoot {
\r
35 get { return this; }
\r
38 public void CopyTo (Array array, int arrayIndex)
\r
40 list.CopyTo (array, arrayIndex);
\r
46 public IEnumerator GetEnumerator ()
\r
48 return list.GetEnumerator ();
\r
54 // LAMESPEC: So how is one supposed to create a writable CookieCollection
\r
55 // instance?? We simply ignore this property, as this collection is always
\r
57 public bool IsReadOnly {
\r
58 get { return true; }
\r
61 // LAMESPEC: Which exception should we throw when the read only
\r
62 // property is set to true??
\r
63 public void Add (Cookie cookie)
\r
66 throw new ArgumentNullException ("cookie");
\r
67 int pos = list.IndexOf (cookie);
\r
71 list [pos] = cookie;
\r
74 // LAMESPEC: Which exception should we throw when the read only
\r
75 // property is set to true??
\r
76 public void Add (CookieCollection cookies)
\r
78 if (cookies == null)
\r
79 throw new ArgumentNullException ("cookies");
\r
81 IEnumerator enumerator = cookies.list.GetEnumerator ();
\r
82 while (enumerator.MoveNext ())
\r
83 Add ((Cookie) enumerator.Current);
\r
86 public Cookie this [int index] {
\r
88 if (index < 0 || index >= list.Count)
\r
89 throw new ArgumentOutOfRangeException ("index");
\r
90 return (Cookie) list [index];
\r
94 public Cookie this [string name] {
\r
97 IEnumerator enumerator = list.GetEnumerator ();
\r
98 while (enumerator.MoveNext ())
\r
99 if (String.Compare (((Cookie) enumerator.Current).Name, name, true) == 0)
\r
100 return (Cookie) enumerator.Current;
\r
107 } // CookieCollection
\r