2
0

DataTableMappingCollection.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. //
  2. // System.Data.Common.DataTableMappingCollection.cs
  3. //
  4. // Author:
  5. // Rodrigo Moya ([email protected])
  6. // Tim Coleman ([email protected])
  7. //
  8. // (C) Ximian, Inc
  9. // Copyright (C) 2002 Tim Coleman
  10. //
  11. using System;
  12. using System.Collections;
  13. namespace System.Data.Common
  14. {
  15. /// <summary>
  16. /// A collection of DataTableMapping objects. This class cannot be inherited.
  17. /// </summary>
  18. public sealed class DataTableMappingCollection : MarshalByRefObject, ITableMappingCollection, IList, ICollection, IEnumerable
  19. {
  20. #region Fields
  21. ArrayList mappings;
  22. Hashtable sourceTables;
  23. Hashtable dataSetTables;
  24. #endregion
  25. #region Constructors
  26. public DataTableMappingCollection()
  27. {
  28. mappings = new ArrayList ();
  29. sourceTables = new Hashtable ();
  30. dataSetTables = new Hashtable ();
  31. }
  32. #endregion
  33. #region Properties
  34. public int Count
  35. {
  36. get { return mappings.Count; }
  37. }
  38. public DataTableMapping this[int index] {
  39. get { return (DataTableMapping)(mappings[index]); }
  40. set {
  41. DataTableMapping mapping = (DataTableMapping)(mappings[index]);
  42. sourceTables[mapping.SourceTable] = value;
  43. dataSetTables[mapping.DataSetTable] = value;
  44. mappings[index] = value;
  45. }
  46. }
  47. [MonoTODO]
  48. public DataTableMapping this[string sourceTable] {
  49. get { return (DataTableMapping)(sourceTables[sourceTable]); }
  50. set { this[mappings.IndexOf(sourceTables[sourceTable])] = value; }
  51. }
  52. object IList.this[int index] {
  53. get { return (object)(this[index]); }
  54. set {
  55. if (!(value is DataTableMapping))
  56. throw new ArgumentException ();
  57. this[index] = (DataTableMapping)value;
  58. }
  59. }
  60. bool IList.IsReadOnly {
  61. get { return false; }
  62. }
  63. bool IList.IsFixedSize {
  64. get { return false; }
  65. }
  66. object ICollection.SyncRoot {
  67. get { return mappings.SyncRoot; }
  68. }
  69. bool ICollection.IsSynchronized {
  70. get { return mappings.IsSynchronized; }
  71. }
  72. object ITableMappingCollection.this[string sourceTable] {
  73. get { return this[sourceTable]; }
  74. set {
  75. if (!(value is DataTableMapping))
  76. throw new ArgumentException ();
  77. this[sourceTable] = (DataTableMapping)(value);
  78. }
  79. }
  80. #endregion
  81. #region Methods
  82. public int Add (object value)
  83. {
  84. if (!(value is System.Data.Common.DataTableMapping))
  85. throw new SystemException ("The object passed in was not a DataTableMapping object.");
  86. sourceTables[((DataTableMapping)value).SourceTable] = value;
  87. dataSetTables[((DataTableMapping)value).DataSetTable] = value;
  88. return mappings.Add (value);
  89. }
  90. public DataTableMapping Add (string sourceTable, string dataSetTable)
  91. {
  92. DataTableMapping mapping = new DataTableMapping (sourceTable, dataSetTable);
  93. Add (mapping);
  94. return mapping;
  95. }
  96. public void AddRange(DataTableMapping[] values)
  97. {
  98. foreach (DataTableMapping dataTableMapping in values)
  99. this.Add (dataTableMapping);
  100. }
  101. public void Clear()
  102. {
  103. sourceTables.Clear ();
  104. dataSetTables.Clear ();
  105. mappings.Clear ();
  106. }
  107. public bool Contains (object value)
  108. {
  109. return mappings.Contains (value);
  110. }
  111. public bool Contains (string value)
  112. {
  113. return sourceTables.Contains (value);
  114. }
  115. [MonoTODO]
  116. public void CopyTo(Array array, int index)
  117. {
  118. throw new NotImplementedException ();
  119. }
  120. public DataTableMapping GetByDataSetTable (string dataSetTable)
  121. {
  122. return (DataTableMapping)(dataSetTables[dataSetTable]);
  123. }
  124. public static DataTableMapping GetTableMappingBySchemaAction (DataTableMappingCollection tableMappings, string sourceTable, string dataSetTable, MissingMappingAction mappingAction)
  125. {
  126. if (tableMappings.Contains (sourceTable))
  127. return tableMappings[sourceTable];
  128. if (mappingAction == MissingMappingAction.Error)
  129. throw new InvalidOperationException ();
  130. if (mappingAction == MissingMappingAction.Ignore)
  131. return null;
  132. return new DataTableMapping (sourceTable, dataSetTable);
  133. }
  134. public IEnumerator GetEnumerator ()
  135. {
  136. return mappings.GetEnumerator ();
  137. }
  138. public int IndexOf (object value)
  139. {
  140. return mappings.IndexOf (value);
  141. }
  142. public int IndexOf (string sourceTable)
  143. {
  144. return IndexOf (sourceTables[sourceTable]);
  145. }
  146. public int IndexOfDataSetTable (string dataSetTable)
  147. {
  148. return IndexOf ((DataTableMapping)(dataSetTables[dataSetTable]));
  149. }
  150. [MonoTODO]
  151. public void Insert (int index, object value)
  152. {
  153. throw new NotImplementedException ();
  154. }
  155. [MonoTODO]
  156. ITableMapping ITableMappingCollection.Add (string sourceTableName, string dataSetTableName)
  157. {
  158. throw new NotImplementedException ();
  159. }
  160. [MonoTODO]
  161. ITableMapping ITableMappingCollection.GetByDataSetTable (string dataSetTableName)
  162. {
  163. throw new NotImplementedException ();
  164. }
  165. [MonoTODO]
  166. public void Remove (object value)
  167. {
  168. throw new NotImplementedException ();
  169. }
  170. [MonoTODO]
  171. public void RemoveAt (int index)
  172. {
  173. throw new NotImplementedException ();
  174. }
  175. [MonoTODO]
  176. public void RemoveAt (string index)
  177. {
  178. throw new NotImplementedException ();
  179. }
  180. #endregion
  181. }
  182. }