mscorlib(4.0.0.0) API with additions
CookieCollection.cs
1 using System.Collections;
3 
4 namespace System.Net
5 {
8  [global::__DynamicallyInvokable]
10  {
11  internal enum Stamp
12  {
13  Check,
14  Set,
15  SetToUnused,
16  SetToMaxUsed
17  }
18 
19  private class CookieCollectionEnumerator : IEnumerator
20  {
21  private CookieCollection m_cookies;
22 
23  private int m_count;
24 
25  private int m_index = -1;
26 
27  private int m_version;
28 
29  object IEnumerator.Current
30  {
31  get
32  {
33  if (m_index < 0 || m_index >= m_count)
34  {
35  throw new InvalidOperationException(SR.GetString("InvalidOperation_EnumOpCantHappen"));
36  }
37  if (m_version != m_cookies.m_version)
38  {
39  throw new InvalidOperationException(SR.GetString("InvalidOperation_EnumFailedVersion"));
40  }
41  return m_cookies[m_index];
42  }
43  }
44 
45  internal CookieCollectionEnumerator(CookieCollection cookies)
46  {
47  m_cookies = cookies;
48  m_count = cookies.Count;
49  m_version = cookies.m_version;
50  }
51 
52  bool IEnumerator.MoveNext()
53  {
54  if (m_version != m_cookies.m_version)
55  {
56  throw new InvalidOperationException(SR.GetString("InvalidOperation_EnumFailedVersion"));
57  }
58  if (++m_index < m_count)
59  {
60  return true;
61  }
62  m_index = m_count;
63  return false;
64  }
65 
66  void IEnumerator.Reset()
67  {
68  m_index = -1;
69  }
70  }
71 
72  internal int m_version;
73 
74  private ArrayList m_list = new ArrayList();
75 
76  private DateTime m_TimeStamp = DateTime.MinValue;
77 
78  private bool m_has_other_versions;
79 
80  [OptionalField]
81  private bool m_IsReadOnly;
82 
86  public bool IsReadOnly => m_IsReadOnly;
87 
93  public Cookie this[int index]
94  {
95  get
96  {
97  if (index < 0 || index >= m_list.Count)
98  {
99  throw new ArgumentOutOfRangeException("index");
100  }
101  return (Cookie)m_list[index];
102  }
103  }
104 
110  [global::__DynamicallyInvokable]
111  public Cookie this[string name]
112  {
113  [global::__DynamicallyInvokable]
114  get
115  {
116  foreach (Cookie item in m_list)
117  {
118  if (string.Compare(item.Name, name, StringComparison.OrdinalIgnoreCase) == 0)
119  {
120  return item;
121  }
122  }
123  return null;
124  }
125  }
126 
129  [global::__DynamicallyInvokable]
130  public int Count
131  {
132  [global::__DynamicallyInvokable]
133  get
134  {
135  return m_list.Count;
136  }
137  }
138 
142  public bool IsSynchronized => false;
143 
146  public object SyncRoot => this;
147 
148  internal bool IsOtherVersionSeen => m_has_other_versions;
149 
151  [global::__DynamicallyInvokable]
153  {
154  m_IsReadOnly = true;
155  }
156 
157  internal CookieCollection(bool IsReadOnly)
158  {
159  m_IsReadOnly = IsReadOnly;
160  }
161 
166  [global::__DynamicallyInvokable]
167  public void Add(Cookie cookie)
168  {
169  if (cookie == null)
170  {
171  throw new ArgumentNullException("cookie");
172  }
173  m_version++;
174  int num = IndexOf(cookie);
175  if (num == -1)
176  {
177  m_list.Add(cookie);
178  }
179  else
180  {
181  m_list[num] = cookie;
182  }
183  }
184 
189  [global::__DynamicallyInvokable]
190  public void Add(CookieCollection cookies)
191  {
192  if (cookies == null)
193  {
194  throw new ArgumentNullException("cookies");
195  }
196  foreach (Cookie cooky in cookies)
197  {
198  Add(cooky);
199  }
200  }
201 
212  public void CopyTo(Array array, int index)
213  {
214  m_list.CopyTo(array, index);
215  }
216 
227  public void CopyTo(Cookie[] array, int index)
228  {
229  m_list.CopyTo(array, index);
230  }
231 
232  internal DateTime TimeStamp(Stamp how)
233  {
234  switch (how)
235  {
236  case Stamp.Set:
237  m_TimeStamp = DateTime.Now;
238  break;
239  case Stamp.SetToMaxUsed:
240  m_TimeStamp = DateTime.MaxValue;
241  break;
242  case Stamp.SetToUnused:
243  m_TimeStamp = DateTime.MinValue;
244  break;
245  }
246  return m_TimeStamp;
247  }
248 
249  internal int InternalAdd(Cookie cookie, bool isStrict)
250  {
251  int result = 1;
252  if (isStrict)
253  {
254  IComparer comparer = Cookie.GetComparer();
255  int num = 0;
256  foreach (Cookie item in m_list)
257  {
258  if (comparer.Compare(cookie, item) == 0)
259  {
260  result = 0;
261  if (item.Variant <= cookie.Variant)
262  {
263  m_list[num] = cookie;
264  }
265  break;
266  }
267  num++;
268  }
269  if (num == m_list.Count)
270  {
271  m_list.Add(cookie);
272  }
273  }
274  else
275  {
276  m_list.Add(cookie);
277  }
278  if (cookie.Version != 1)
279  {
280  m_has_other_versions = true;
281  }
282  return result;
283  }
284 
285  internal int IndexOf(Cookie cookie)
286  {
287  IComparer comparer = Cookie.GetComparer();
288  int num = 0;
289  foreach (Cookie item in m_list)
290  {
291  if (comparer.Compare(cookie, item) == 0)
292  {
293  return num;
294  }
295  num++;
296  }
297  return -1;
298  }
299 
300  internal void RemoveAt(int idx)
301  {
302  m_list.RemoveAt(idx);
303  }
304 
307  [global::__DynamicallyInvokable]
309  {
310  return new CookieCollectionEnumerator(this);
311  }
312  }
313 }
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
void Reset()
Sets the enumerator to its initial position, which is before the first element in the collection.
The Cookie header, which specifies cookie data presented to the server.
bool MoveNext()
Advances the enumerator to the next element of the collection.
StringComparison
Specifies the culture, case, and sort rules to be used by certain overloads of the M:System....
static readonly DateTime MinValue
Represents the smallest possible value of T:System.DateTime. This field is read-only.
Definition: DateTime.cs:109
virtual int Count
Gets the number of elements actually contained in the T:System.Collections.ArrayList.
Definition: ArrayList.cs:2255
Definition: __Canon.cs:3
The exception that is thrown when the value of an argument is outside the allowable range of values a...
Represents an instant in time, typically expressed as a date and time of day. To browse the ....
Definition: DateTime.cs:13
int Compare(object x, object y)
Compares two objects and returns a value indicating whether one is less than, equal to,...
Exposes an enumerator, which supports a simple iteration over a non-generic collection....
Definition: IEnumerable.cs:9
static readonly DateTime MaxValue
Represents the largest possible value of T:System.DateTime. This field is read-only.
Definition: DateTime.cs:113
object Current
Gets the element in the collection at the current position of the enumerator.
Definition: IEnumerator.cs:15
Exposes a method that compares two objects.
Definition: IComparer.cs:8
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition: Array.cs:17
virtual void CopyTo(Array array)
Copies the entire T:System.Collections.ArrayList to a compatible one-dimensional T:System....
Definition: ArrayList.cs:2516
virtual int Add(object value)
Adds an object to the end of the T:System.Collections.ArrayList.
Definition: ArrayList.cs:2381
Specifies that the class can be serialized.
static DateTime Now
Gets a T:System.DateTime object that is set to the current date and time on this computer,...
Definition: DateTime.cs:264
The exception that is thrown when a method call is invalid for the object's current state.
Defines size, enumerators, and synchronization methods for all nongeneric collections.
Definition: ICollection.cs:8
Supports a simple iteration over a non-generic collection.
Definition: IEnumerator.cs:9
Implements the T:System.Collections.IList interface using an array whose size is dynamically increase...
Definition: ArrayList.cs:14