2002-04-17 Rodrigo Moya <rodrigo@ximian.com>
[mono.git] / mcs / class / System.Data / System.Data.Common / DataColumnMappingCollection.cs
1 //
2 // System.Data.Common.DataColumnCollection
3 //
4 // Author:
5 //   Rodrigo Moya (rodrigo@ximian.com)
6 //
7 // (C) Ximian, Inc
8 //
9
10 using System;
11 using System.Data;
12
13 namespace System.Data.Common
14 {
15         /// <summary>
16         /// Contains a collection of DataColumnMapping objects. This class cannot be inherited.
17         /// </summary>
18         public sealed class DataColumnMappingCollection :
19                 MarshalByRefObject, IColumnMappingCollection, IList,
20                 ICollection, IEnumerable
21         {
22                 private DataColumnMapping[] mappings = null;
23                 private int size = 0;
24                 
25                 public DataColumnMappingCollection () {
26                 }
27
28                 public int Add (object obj) {
29                         DataColumnMapping[] tmp = new DataColumnMapping[size + 1];
30
31                         Array.Copy (mappings, tmp, size);
32                         size++;
33                         mappings = tmp;
34                         mappings[size - 1] = obj;
35
36                         return size;
37                 }
38
39                 public void AddRange (DataColumnMapping[] values) {
40                         DataColumnMapping[] tmp = new DataColumnMapping[size + values.Length];
41
42                         Array.Copy (mappings, tmp, size);
43                         for (int i = 0; i < values.Length; i++) {
44                                 tmp[i + size] = values[i];
45                         }
46                         
47                         size += values.Length;
48                         mappings = tmp;
49                 }
50
51                 public void Clear () {
52                         /* FIXME */
53                         for (int i = 0; i < size; i++)
54                                 mappings[i] = null;
55
56                         size = 0;
57                 }
58
59                 public bool Contains (object obj) {
60                         for (int i = 0; i < size; i++) {
61                                 if (obj.Equals (mappings[i]))
62                                     return true;
63                         }
64
65                         return false;
66                 }
67
68                 public void CopyTo (Array array, int index) {
69                         DataColumnMapping[] tmp = new DataColumnMapping[size];
70                         Array.Copy (mappings, tmp, size);
71                 }
72
73                 public DataColumnMapping GetByDataSetColumn (string value) {
74                         for (int i = 0; i < size; i++) {
75                                 if (mappings[i].DataSetColumn == value)
76                                         return mappings[i];
77                         }
78
79                         return null;
80                 }
81
82                 [MonoTODO]
83                 public static DataColumnMapping GetColumnMappingBySchemaAction (
84                         DataColumnMappingCollection columnMappings,
85                         string sourceColumn,
86                         MissingMappingAction mappingAction) {
87                         throw new NotImplementedException ();
88                 }
89
90                 public int IndexOf (object obj) {
91                         for (int i = 0; i < size; i++) {
92                                 if (obj.Equals (mappings[i]))
93                                         return i;
94                         }
95
96                         return -1;
97                 }
98
99                 public int IndexOfDataSetColumn (string value) {
100                         for (int i = 0; i < size; i++) {
101                                 if (mappings[i].DataSetColumn == value)
102                                         return i;
103                         }
104
105                         return -1;
106                 }
107
108                 [MonoTODO]
109                 public void Insert (int index, object value) {
110                         throw new NotImplementedException ();
111                 }
112
113                 [MonoTODO]
114                 public void Remove (object value) {
115                         throw new NotImplementedException ();
116                 }
117
118                 [MonoTODO]
119                 public void RemoveAt (int index) {
120                         throw new NotImplementedException ();
121                 }
122                 
123                 public int Count {
124                         get { return size; }
125                 }
126
127                 public DataColumnMapping this[int index] {
128                         get {
129                                 if (value < size)
130                                         return mappings[index];
131                                 return null;
132                         }
133                         set {
134                                 if (value < size)
135                                         mappings[index] = value;
136                         }
137                 }
138         }
139 }