New tests, updates
[mono.git] / mcs / class / System.Data / System.Data / InternalDataCollectionBase.cs
1 //
2 // System.Data.InternalDataCollectionBase.cs
3 //
4 // Base class for:
5 //     DataRowCollection
6 //     DataColumnCollection
7 //     DataTableCollection
8 //     DataRelationCollection
9 //     DataConstraintCollection
10 //
11 // Author:
12 //   Daniel Morgan <danmorg@sc.rr.com>
13 //   Tim Coleman <tim@timcoleman.com>
14 //
15 // (C) Copyright 2002 Daniel Morgan
16 // (C) Copyright 2002 Tim Coleman
17 //
18
19 //
20 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
21 //
22 // Permission is hereby granted, free of charge, to any person obtaining
23 // a copy of this software and associated documentation files (the
24 // "Software"), to deal in the Software without restriction, including
25 // without limitation the rights to use, copy, modify, merge, publish,
26 // distribute, sublicense, and/or sell copies of the Software, and to
27 // permit persons to whom the Software is furnished to do so, subject to
28 // the following conditions:
29 //
30 // The above copyright notice and this permission notice shall be
31 // included in all copies or substantial portions of the Software.
32 //
33 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
34 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
35 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
36 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
37 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
38 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
39 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
40 //
41
42 using System;
43 using System.Collections;
44 using System.ComponentModel;
45
46 namespace System.Data
47 {
48         /// <summary>
49         /// Base class for System.Data collection classes
50         /// that are used within a DataTable object
51         /// to represent a collection of
52         /// relations, tables, rows, columns, and constraints
53         /// </summary>
54
55         public class InternalDataCollectionBase : ICollection, IEnumerable {
56                 #region Fields
57
58                 private ArrayList list = null;
59                 private bool readOnly = false;
60                 private bool synchronized = false;
61
62                 #endregion
63
64                 #region Constructors
65
66                 public InternalDataCollectionBase ()
67                 {
68                         list = new ArrayList();
69                 }
70
71                 #endregion
72
73                 #region Properties
74
75                 /// <summary>
76                 /// Gets the total number of elements in a collection.
77                 /// </summary>
78                 [Browsable (false)]
79                 public virtual int Count {
80                         get { return list.Count; }
81                 }
82
83                 /// <summary>
84                 /// Gets a value indicating whether the InternalDataCollectionBase is read-only.
85                 /// </summary>
86                 [Browsable (false)]
87                 public bool IsReadOnly {
88                         get { return readOnly; }
89                 }
90
91                 /// <summary>
92                 /// Gets a value indicating whether the InternalDataCollectionBase is synchronized.
93                 /// </summary>
94                 [Browsable (false)]
95                 public bool IsSynchronized {
96                         get { return synchronized; }
97                 }
98
99                 /// <summary>
100                 /// Gets the items of the collection as a list.
101                 /// </summary>
102                 protected virtual ArrayList List {
103                         get { return list; }
104                 }
105
106                 /// <summary>
107                 /// Gets an object that can be used to synchronize the collection.
108                 /// </summary>
109                 [Browsable (false)]
110                 public object SyncRoot {
111                         get { return this; }
112                 }
113
114
115                 #endregion
116
117                 #region Methods
118
119                 /// <summary>
120                 /// Copies all the elements in the current InternalDataCollectionBase to a one-
121                 /// dimensional Array, starting at the specified InternalDataCollectionBase index.
122                 /// </summary>
123                 public
124 #if NET_2_0
125                 virtual
126 #endif
127                 void CopyTo (Array ar, int index)
128                 {
129                         list.CopyTo (ar, index);
130                 }
131
132                 /// <summary>
133                 /// Gets an IEnumerator for the collection.
134                 /// </summary>
135                 public
136 #if NET_2_0
137                 virtual
138 #endif
139                 IEnumerator GetEnumerator ()
140                 {
141                         return list.GetEnumerator ();
142                 }
143
144                 internal Array ToArray (Type type)
145                 {
146                         return list.ToArray (type);
147                 }
148
149                 #endregion
150         }
151 }