2
0

DataTableMappingCollection.cs 5.8 KB

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