+
+#if NET_2_0
+ sealed partial class DataTableCollection {
+ public DataTable this [string name, string tableNamespace] {
+ get {
+ int index = IndexOf (name, tableNamespace, true);
+ return index < 0 ? null : (DataTable) List [index];
+ }
+ }
+
+ public DataTable Add (string name, string tableNamespace)
+ {
+ DataTable table = new DataTable (name, tableNamespace);
+ this.Add (table);
+ return table;
+ }
+
+ public bool Contains (string name, string tableNamespace)
+ {
+ return (IndexOf (name, tableNamespace) != -1);
+ }
+
+ public int IndexOf (string tableName, string tableNamespace)
+ {
+ if (tableNamespace == null)
+ throw new ArgumentNullException ("'tableNamespace' argument cannot be null.",
+ "tableNamespace");
+ return IndexOf (tableName, tableNamespace, false);
+ }
+
+ public void Remove (string name, string tableNamespace)
+ {
+ int index = IndexOf (name, tableNamespace, true);
+ if (index == -1)
+ throw new ArgumentException ("Table " + name + " does not belong to this DataSet");
+
+ RemoveAt (index);
+ }
+
+ private int IndexOf (string name, string ns, bool error)
+ {
+ int index = -1, count = 0, match = -1;
+ do {
+ index = IndexOf (name, error, index+1);
+
+ if (index == -1)
+ break;
+
+ if (ns == null) {
+ if (count > 1)
+ break;
+ count++;
+ match = index;
+ } else if (this [index].Namespace.Equals (ns))
+ return index;
+
+ } while (index != -1 && index < Count);
+
+ if (count == 1)
+ return match;
+
+ if (count == 0 || !error)
+ return -1;
+
+ throw new ArgumentException ("The given name '" + name + "' matches atleast two names" +
+ "in the collection object with different namespaces");
+ }
+
+ private int IndexOf (string name, bool error)
+ {
+ return IndexOf (name, null, error);
+ }
+
+ public void CopyTo (DataTable [] array, int index)
+ {
+ CopyTo ((Array) array, index);
+ }
+
+ internal void BinarySerialize_Schema (SerializationInfo si)
+ {
+ si.AddValue ("DataSet.Tables.Count", Count);
+ for (int i = 0; i < Count; i++) {
+ DataTable dt = (DataTable) List [i];
+
+ if (dt.dataSet != dataSet)
+ throw new SystemException ("Internal Error: inconsistent DataTable");
+
+ MemoryStream ms = new MemoryStream ();
+ BinaryFormatter bf = new BinaryFormatter ();
+ bf.Serialize (ms, dt);
+ byte [] serializedStream = ms.ToArray ();
+ ms.Close ();
+ si.AddValue ("DataSet.Tables_" + i, serializedStream, typeof (Byte []));
+ }
+ }
+
+ internal void BinarySerialize_Data (SerializationInfo si)
+ {
+ for (int i = 0; i < Count; i++) {
+ DataTable dt = (DataTable) List [i];
+ for (int j = 0; j < dt.Columns.Count; j++) {
+ si.AddValue ("DataTable_" + i + ".DataColumn_" + j + ".Expression",
+ dt.Columns[j].Expression);
+ }
+ dt.BinarySerialize (si, "DataTable_" + i + ".");
+ }
+ }
+ }
+#else
+ [Serializable]
+ partial class DataTableCollection {
+ private int IndexOf (string name, bool error)
+ {
+ return IndexOf (name, error, 0);
+ }
+ }
+#endif