Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mcs / class / referencesource / System.Web / Util / SingleObjectCollection.cs
1 //------------------------------------------------------------------------------
2 // <copyright file="SingleObjectCollection.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>                                                                
5 //------------------------------------------------------------------------------
6
7 /*
8  * SingleObjectCollection class
9  * 
10  * Copyright (c) 1999 Microsoft Corporation
11  */
12
13 namespace System.Web.Util {
14
15 using System.Collections;
16
17 /*
18  * Fast implementation of a collection with a single object
19  */
20 internal class SingleObjectCollection: ICollection {
21
22     private class SingleObjectEnumerator: IEnumerator {
23         private object _object;
24         private bool done;
25
26         public SingleObjectEnumerator(object o) { _object = o; }
27         public object Current { get { return _object; } }
28         public bool MoveNext() {
29             if (!done) {
30                 done = true;
31                 return true;
32             }
33
34             return false;
35         }
36         public void Reset() { done = false; }
37     }
38
39     private object _object;
40
41     public SingleObjectCollection(object o) { _object = o; }
42
43     IEnumerator IEnumerable.GetEnumerator() { return new SingleObjectEnumerator(_object); }
44     public int Count { get { return 1; } }
45     bool ICollection.IsSynchronized { get { return true; } }
46     object ICollection.SyncRoot { get { return this; } }
47
48     public void CopyTo(Array array, int index) {
49         array.SetValue(_object, index);
50     }
51 }
52
53 }