2 // System.Web.HttpCookieCollection
5 // Patrik Torstensson (Patrik.Torstensson@labs2.com)
6 // (First impl Bob Smith <bob@thestuff.net>)
11 using System.Collections.Specialized;
15 public sealed class HttpCookieCollection : NameObjectCollectionBase
17 HttpCookie [] _AllCookies;
20 HttpResponse _Response;
22 internal HttpCookieCollection(HttpResponse Response, bool ReadOnly) : base()
25 IsReadOnly = ReadOnly;
28 public HttpCookieCollection () { }
30 public string [] AllKeys
34 _AllKeys = BaseGetAllKeys ();
40 public HttpCookie this [int index]
42 get { return Get (index); }
45 public HttpCookie this [string name]
47 get { return Get (name); }
50 public void Add (HttpCookie cookie)
52 if (null != _Response)
53 _Response.GoingToChangeCookieColl ();
55 // empy performance cache
59 BaseAdd (cookie.Name, cookie);
61 if (null != _Response)
62 _Response.OnCookieAdd (cookie);
72 public void CopyTo (Array dest, int index)
74 if (null == _AllCookies) {
75 _AllCookies = new HttpCookie [Count];
77 for (int i = 0; i != Count; i++)
78 _AllCookies [i] = Get (i);
81 _AllCookies.CopyTo (dest, index);
84 public HttpCookie Get (int index)
86 return BaseGet (index) as HttpCookie;
89 public HttpCookie Get (string name)
91 HttpCookie oRet = BaseGet (name) as HttpCookie;
92 if (null == oRet && _Response != null) {
96 _Response.GoingToChangeCookieColl ();
98 oRet = new HttpCookie (name);
101 _Response.OnCookieAdd (oRet);
107 public string GetKey (int index)
109 return BaseGetKey (index);
112 public void Remove (string name)
114 if (null != _Response)
115 _Response.GoingToChangeCookieColl ();
121 if (null != _Response)
122 _Response.ChangedCookieColl ();
125 public void Set (HttpCookie cookie)
127 if (null != _Response)
128 _Response.GoingToChangeCookieColl ();
132 BaseSet (cookie.Name, cookie);
134 if (null != _Response)
135 _Response.ChangedCookieColl();