2 // System.Data.Common.DataTableMappingCollection.cs
5 // Rodrigo Moya (rodrigo@ximian.com)
6 // Tim Coleman (tim@timcoleman.com)
9 // Copyright (C) 2002 Tim Coleman
13 using System.Collections;
15 namespace System.Data.Common
18 /// A collection of DataTableMapping objects. This class cannot be inherited.
20 public sealed class DataTableMappingCollection : MarshalByRefObject, ITableMappingCollection, IList, ICollection, IEnumerable
25 Hashtable sourceTables;
26 Hashtable dataSetTables;
32 public DataTableMappingCollection()
34 mappings = new ArrayList ();
35 sourceTables = new Hashtable ();
36 dataSetTables = new Hashtable ();
45 get { return mappings.Count; }
48 public DataTableMapping this[int index] {
49 get { return (DataTableMapping)(mappings[index]); }
51 DataTableMapping mapping = (DataTableMapping)(mappings[index]);
52 sourceTables[mapping.SourceTable] = value;
53 dataSetTables[mapping.DataSetTable] = value;
54 mappings[index] = value;
59 public DataTableMapping this[string sourceTable] {
60 get { return (DataTableMapping)(sourceTables[sourceTable]); }
61 set { this[mappings.IndexOf(sourceTables[sourceTable])] = value; }
65 object IList.this[int index] {
66 get { return (object)(this[index]); }
68 if (!(value is DataTableMapping))
69 throw new ArgumentException ();
70 this[index] = (DataTableMapping)value;
74 bool IList.IsReadOnly {
78 bool IList.IsFixedSize {
82 object ICollection.SyncRoot {
83 get { return mappings.SyncRoot; }
86 bool ICollection.IsSynchronized {
87 get { return mappings.IsSynchronized; }
90 object ITableMappingCollection.this[string sourceTable] {
91 get { return this[sourceTable]; }
93 if (!(value is DataTableMapping))
94 throw new ArgumentException ();
95 this[sourceTable] = (DataTableMapping)(value);
103 public int Add (object value)
105 if (!(value is System.Data.Common.DataTableMapping))
106 throw new SystemException ("The object passed in was not a DataTableMapping object.");
108 sourceTables[((DataTableMapping)value).SourceTable] = value;
109 dataSetTables[((DataTableMapping)value).DataSetTable] = value;
110 return mappings.Add (value);
113 public DataTableMapping Add (string sourceTable, string dataSetTable)
115 DataTableMapping mapping = new DataTableMapping (sourceTable, dataSetTable);
120 public void AddRange(DataTableMapping[] values)
122 foreach (DataTableMapping dataTableMapping in values)
123 this.Add (dataTableMapping);
128 sourceTables.Clear ();
129 dataSetTables.Clear ();
133 public bool Contains (object value)
135 return mappings.Contains (value);
138 public bool Contains (string value)
140 return sourceTables.Contains (value);
144 public void CopyTo(Array array, int index)
146 throw new NotImplementedException ();
149 public DataTableMapping GetByDataSetTable (string dataSetTable)
151 return (DataTableMapping)(dataSetTables[dataSetTable]);
154 public static DataTableMapping GetTableMappingBySchemaAction (DataTableMappingCollection tableMappings, string sourceTable, string dataSetTable, MissingMappingAction mappingAction)
156 if (tableMappings.Contains (sourceTable))
157 return tableMappings[sourceTable];
158 if (mappingAction == MissingMappingAction.Error)
159 throw new InvalidOperationException ();
160 if (mappingAction == MissingMappingAction.Ignore)
162 return new DataTableMapping (sourceTable, dataSetTable);
165 public IEnumerator GetEnumerator ()
167 return mappings.GetEnumerator ();
170 public int IndexOf (object value)
172 return mappings.IndexOf (value);
175 public int IndexOf (string sourceTable)
177 return IndexOf (sourceTables[sourceTable]);
180 public int IndexOfDataSetTable (string dataSetTable)
182 return IndexOf ((DataTableMapping)(dataSetTables[dataSetTable]));
186 public void Insert (int index, object value)
188 throw new NotImplementedException ();
192 ITableMapping ITableMappingCollection.Add (string sourceTableName, string dataSetTableName)
194 throw new NotImplementedException ();
198 ITableMapping ITableMappingCollection.GetByDataSetTable (string dataSetTableName)
200 throw new NotImplementedException ();
204 public void Remove (object value)
206 throw new NotImplementedException ();
210 public void RemoveAt (int index)
212 throw new NotImplementedException ();
216 public void RemoveAt (string index)
218 throw new NotImplementedException ();