[corlib] Improve CancellationTokenSource test
[mono.git] / mcs / class / System.DirectoryServices / System.DirectoryServices / SearchResultCollection.cs
1 /******************************************************************************
2 * The MIT License
3 * Copyright (c) 2003 Novell Inc.,  www.novell.com
4
5 * Permission is hereby granted, free of charge, to any person obtaining  a copy
6 * of this software and associated documentation files (the Software), to deal
7 * in the Software without restriction, including  without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
9 * copies of the Software, and to  permit persons to whom the Software is 
10 * furnished to do so, subject to the following conditions:
11
12 * The above copyright notice and this permission notice shall be included in 
13 * all copies or substantial portions of the Software.
14
15 * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 *******************************************************************************/
23
24 //
25 // System.DirectoryServices.SearchResultCollection.cs
26 //
27 // Author:
28 //   Sunil Kumar (sunilk@novell.com)
29 //
30 // (C)  Novell Inc.
31 //
32
33 using System;
34 using System.Collections;
35
36 namespace System.DirectoryServices
37 {
38         /// <summary>
39         /// Contains the SearchResult instances that the Active Directory 
40         /// hierarchy returned during a DirectorySearcher query.
41         /// </summary>
42         /// <remarks>
43         /// Each time you perform a query, DirectorySearcher creates a handle to 
44         /// the corresponding SearchResultCollection instance. This handle 
45         /// persists until you call Dispose or until garbage collection picks up 
46         /// the instance.
47         /// </remarks>
48         public class SearchResultCollection : MarshalByRefObject, ICollection, IEnumerable, IDisposable
49         {
50                 private ArrayList sValues = new ArrayList();
51
52                 internal SearchResultCollection()
53                 {
54                 }
55                 
56                 public int Count
57                 {
58                         get{return sValues.Count;}
59                 }
60
61                 bool ICollection.IsSynchronized
62                 {
63                         get{return sValues.IsSynchronized;}
64                 }
65
66                 object ICollection.SyncRoot
67                 {
68                         get{return sValues.SyncRoot;}
69                 }
70         
71                 void ICollection.CopyTo(System.Array oArray, int iArrayIndex)
72                 {
73                         sValues.CopyTo(oArray, iArrayIndex);
74                 }
75
76                 public void CopyTo(SearchResult[] results, int index)
77                 {
78                         ((ICollection) this).CopyTo((System.Array)results,index);
79                 }
80
81                 internal void Add(object oValue)
82                 {
83                         sValues.Add(oValue);
84                 }
85 /*
86                 public bool IsFixedSize
87                 {
88                         get{return m_oKeys.IsFixedSize;}
89                 }
90
91                 public bool IsReadOnly
92                 {
93                         get{return m_oKeys.IsReadOnly;}
94                 }
95
96                 public ICollection Keys
97                 {
98                         get{return m_oValues.Keys;}
99                 }
100         
101                 public void Clear()
102                 {
103                         m_oValues.Clear();
104                         m_oKeys.Clear();
105                 }
106
107                 public bool Contains(object oKey)
108                 {
109                         return m_oValues.Contains(oKey);
110                 }
111
112                 public bool ContainsKey(object oKey)
113                 {
114                         return m_oValues.ContainsKey(oKey);
115                 }
116
117                 public IDictionaryEnumerator GetEnumerator()
118                 {
119                         return m_oValues.GetEnumerator();
120                 }    
121
122                 public void Remove(object oKey)
123                 {
124                         m_oValues.Remove(oKey);
125                         m_oKeys.Remove(oKey);
126                 }
127        
128                 public object this[object oKey]
129                 {
130                         get{return m_oValues[oKey];}
131                         set{m_oValues[oKey] = value;}
132                 }
133 */
134                 bool Contains(object oValues)
135                 {
136                         return sValues.Contains(oValues);
137                 }
138
139                 public bool Contains (SearchResult result)
140                 {
141                         return sValues.Contains (result);
142                 }
143
144                 public SearchResult this[int index]
145                 {
146                         get{return (SearchResult)sValues[index];}
147                 }
148
149 /*              public ICollection Values
150                 {
151                         get{return m_oValues.Values;}
152                 }
153 */
154                 public int IndexOf (SearchResult result)
155                 {
156                         return sValues.IndexOf(result);
157                 }
158
159                 public IEnumerator GetEnumerator()
160                 {
161                         return sValues.GetEnumerator();
162                 }
163
164                 public void Dispose ()
165                 {
166                         Dispose (true);
167                         GC.SuppressFinalize (this);
168                 }
169
170                 [MonoTODO]
171                 protected virtual void Dispose (bool disposing)
172                 {
173                 }
174
175                 public string[] PropertiesLoaded
176                 {
177                         [MonoTODO]
178                         get { throw new NotImplementedException (); }
179                 }
180
181                 public IntPtr Handle
182                 {
183                         [MonoTODO]
184                         get { throw new NotImplementedException (); }
185                 }
186
187                 ~SearchResultCollection ()
188                 {
189                         Dispose (false);
190                 }
191         }
192 }
193