2010-07-23 Veerapuram Varadhan <v.varadhan@gmail.com>
[mono.git] / mcs / class / System.Data / System.Data / DataSet.cs
index ac1f6a06984209a80190cc0ff2f099c46348f591..b62aff1e4d7847ae0836161b9f48aadd6d63d6ca 100644 (file)
@@ -1,4 +1,4 @@
-// \r
+//\r
 // System.Data/DataSet.cs\r
 //\r
 // Author:\r
 // distribute, sublicense, and/or sell copies of the Software, and to\r
 // permit persons to whom the Software is furnished to do so, subject to\r
 // the following conditions:\r
-// \r
+//\r
 // The above copyright notice and this permission notice shall be\r
 // included in all copies or substantial portions of the Software.\r
-// \r
+//\r
 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
@@ -45,32 +45,22 @@ using System.Globalization;
 using System.Threading;\r
 using System.IO;\r
 using System.Runtime.Serialization;\r
-#if NET_2_0\r
 using System.Runtime.Serialization.Formatters.Binary;\r
-#endif\r
 using System.Xml;\r
 using System.Xml.Schema;\r
 using System.Xml.Serialization;\r
 using System.Data.Common;\r
 \r
-namespace System.Data {\r
-\r
+namespace System.Data\r
+{\r
        [ToolboxItem ("Microsoft.VSDesigner.Data.VS.DataSetToolboxItem, " + Consts.AssemblyMicrosoft_VSDesigner)]\r
        [DefaultProperty ("DataSetName")]\r
        [DesignerAttribute ("Microsoft.VSDesigner.Data.VS.DataSetDesigner, "+ Consts.AssemblyMicrosoft_VSDesigner, "System.ComponentModel.Design.IDesigner")]\r
-#if NET_2_0\r
-       [XmlSchemaProvider ("GetDataSetSchema")]\r
-       [XmlRootAttribute ("DataSet")]\r
-#endif\r
        [Serializable]\r
-       public class DataSet : MarshalByValueComponent, IListSource, ISupportInitialize,\r
-                              ISerializable, IXmlSerializable\r
-#if NET_2_0\r
-                              , ISupportInitializeNotification\r
-#endif\r
-       {\r
+       public partial class DataSet : MarshalByValueComponent, IListSource, ISupportInitialize,\r
+                              ISerializable, IXmlSerializable {\r
                private string dataSetName;\r
-               private string _namespace = "";\r
+               private string _namespace = string.Empty;\r
                private string prefix;\r
                private bool caseSensitive;\r
                private bool enforceConstraints = true;\r
@@ -78,42 +68,47 @@ namespace System.Data {
                private DataRelationCollection relationCollection;\r
                private PropertyCollection properties;\r
                private DataViewManager defaultView;\r
-               private CultureInfo locale = System.Threading.Thread.CurrentThread.CurrentCulture;\r
-               internal XmlDataDocument _xmlDataDocument = null;\r
+               private CultureInfo locale;\r
+               internal XmlDataDocument _xmlDataDocument;\r
+\r
 #if NET_2_0\r
-               private bool dataSetInitialized = true;\r
+               internal TableAdapterSchemaInfo tableAdapterSchemaInfo;\r
 #endif\r
-               \r
-               bool initInProgress = false;\r
+               bool initInProgress;\r
+\r
                #region Constructors\r
 \r
-               public DataSet () : this ("NewDataSet") \r
-               {               \r
+               public DataSet ()\r
+                       : this ("NewDataSet")\r
+               {\r
                }\r
-               \r
-               public DataSet (string name)\r
+\r
+               public DataSet (string dataSetName)\r
                {\r
-                       dataSetName = name;\r
+                       this.dataSetName = dataSetName;\r
                        tableCollection = new DataTableCollection (this);\r
                        relationCollection = new DataRelationCollection.DataSetRelationCollection (this);\r
                        properties = new PropertyCollection ();\r
-                       this.prefix = String.Empty;\r
-                       \r
-                       this.Locale = CultureInfo.CurrentCulture;\r
+                       prefix = String.Empty;\r
                }\r
 \r
-               protected DataSet (SerializationInfo info, StreamingContext context) : this ()\r
+               protected DataSet (SerializationInfo info, StreamingContext context)\r
+                       : this ()\r
                {\r
+#if NET_2_0\r
+                       if (IsBinarySerialized (info, context)) {\r
+                               BinaryDeserialize (info);\r
+                               return;\r
+                       }\r
+#endif\r
+                       string s = info.GetValue ("XmlSchema", typeof (String)) as String;\r
+                       XmlTextReader reader = new XmlTextReader (new StringReader (s));\r
+                       ReadXmlSchema (reader);\r
+                       reader.Close ();\r
+\r
                        GetSerializationData (info, context);\r
                }\r
 \r
-#if NET_2_0\r
-               [MonoTODO]\r
-               protected DataSet (SerializationInfo info, StreamingContext context, bool constructSchema)\r
-                       : this (info, context)\r
-               {\r
-               }\r
-#endif\r
                #endregion // Constructors\r
 \r
                #region Public Properties\r
@@ -124,45 +119,30 @@ namespace System.Data {
 #endif\r
                [DefaultValue (false)]\r
                public bool CaseSensitive {\r
-                       get {\r
-                               return caseSensitive;\r
-                       } \r
+                       get { return caseSensitive; }\r
                        set {\r
-                               caseSensitive = value; \r
+                               caseSensitive = value;\r
                                if (!caseSensitive) {\r
                                        foreach (DataTable table in Tables) {\r
-                                               table.ResetCaseSensitiveIndexes();\r
+                                               table.ResetCaseSensitiveIndexes ();\r
                                                foreach (Constraint c in table.Constraints)\r
                                                        c.AssertConstraint ();\r
                                        }\r
-                               }\r
-                               else {\r
+                               } else {\r
                                        foreach (DataTable table in Tables) {\r
-                                               table.ResetCaseSensitiveIndexes();\r
+                                               table.ResetCaseSensitiveIndexes ();\r
                                        }\r
                                }\r
                        }\r
                }\r
 \r
-#if NET_2_0\r
-               SerializationFormat remotingFormat = SerializationFormat.Xml;\r
-               [DefaultValue (SerializationFormat.Xml)]\r
-               public SerializationFormat RemotingFormat {\r
-                       get {\r
-                               return remotingFormat;\r
-                       }\r
-                       set {\r
-                               remotingFormat = value;\r
-                       }\r
-               }\r
-#endif\r
                [DataCategory ("Data")]\r
 #if !NET_2_0\r
                [DataSysDescription ("The name of this DataSet.")]\r
 #endif\r
                [DefaultValue ("")]\r
                public string DataSetName {\r
-                       get { return dataSetName; } \r
+                       get { return dataSetName; }\r
                        set { dataSetName = value; }\r
                }\r
 \r
@@ -175,7 +155,7 @@ namespace System.Data {
                                if (defaultView == null)\r
                                        defaultView = new DataViewManager (this);\r
                                return defaultView;\r
-                       } \r
+                       }\r
                }\r
 \r
 #if !NET_2_0\r
@@ -183,10 +163,8 @@ namespace System.Data {
 #endif\r
                [DefaultValue (true)]\r
                public bool EnforceConstraints {\r
-                       get { return enforceConstraints; } \r
-                       set { \r
-                               InternalEnforceConstraints(value,true);\r
-                       }\r
+                       get { return enforceConstraints; }\r
+                       set { InternalEnforceConstraints (value, true); }\r
                }\r
 \r
                [Browsable (false)]\r
@@ -212,20 +190,12 @@ namespace System.Data {
                        }\r
                }\r
 \r
-#if NET_2_0\r
-               [Browsable (false)]\r
-               public bool IsInitialized {\r
-                       get { return dataSetInitialized;}\r
-               }\r
-#endif\r
                [DataCategory ("Data")]\r
 #if !NET_2_0\r
                [DataSysDescription ("Indicates a locale under which to compare strings within the DataSet.")]\r
 #endif\r
                public CultureInfo Locale {\r
-                       get {\r
-                               return locale;\r
-                       }\r
+                       get { return locale != null ? locale : Thread.CurrentThread.CurrentCulture; }\r
                        set {\r
                                if (locale == null || !locale.Equals (value)) {\r
                                        // TODO: check if the new locale is valid\r
@@ -235,22 +205,33 @@ namespace System.Data {
                        }\r
                }\r
 \r
-               internal void InternalEnforceConstraints(bool value,bool resetIndexes)\r
+               internal bool LocaleSpecified {\r
+                       get { return locale != null; }\r
+               }\r
+\r
+               \r
+#if NET_2_0\r
+               internal TableAdapterSchemaInfo TableAdapterSchemaData {\r
+                       get { return tableAdapterSchemaInfo; }\r
+               }\r
+#endif\r
+               \r
+               internal void InternalEnforceConstraints (bool value,bool resetIndexes)\r
                {\r
-                       if (value == enforceConstraints) \r
+                       if (value == enforceConstraints)\r
                                return;\r
 \r
                        if (value) {\r
                                if (resetIndexes) {\r
                                        // FIXME : is that correct?\r
-                                       // By design  the indexes should be updated at this point.\r
+                                       // By design the indexes should be updated at this point.\r
                                        // In Fill from BeginLoadData till EndLoadData indexes are not updated (reset in EndLoadData)\r
                                        // In DataRow.EndEdit indexes are always updated.\r
                                        foreach (DataTable table in Tables)\r
-                                               table.ResetIndexes();\r
+                                               table.ResetIndexes ();\r
                                }\r
 \r
-                               // TODO : Need to take care of Error handling and settting of RowErrors \r
+                               // TODO : Need to take care of Error handling and settting of RowErrors\r
                                bool constraintViolated = false;\r
                                foreach (DataTable table in Tables) {\r
                                        foreach (Constraint constraint in table.Constraints)\r
@@ -280,39 +261,39 @@ namespace System.Data {
                {\r
                        Merge (table, false, MissingSchemaAction.Add);\r
                }\r
-               \r
+\r
                public void Merge (DataSet dataSet, bool preserveChanges)\r
                {\r
                        Merge (dataSet, preserveChanges, MissingSchemaAction.Add);\r
                }\r
-               \r
+\r
                public void Merge (DataRow[] rows, bool preserveChanges, MissingSchemaAction missingSchemaAction)\r
                {\r
                        if (rows == null)\r
                                throw new ArgumentNullException ("rows");\r
                        if (!IsLegalSchemaAction (missingSchemaAction))\r
                                throw new ArgumentOutOfRangeException ("missingSchemaAction");\r
-                       \r
+\r
                        MergeManager.Merge (this, rows, preserveChanges, missingSchemaAction);\r
                }\r
-               \r
+\r
                public void Merge (DataSet dataSet, bool preserveChanges, MissingSchemaAction missingSchemaAction)\r
                {\r
                        if (dataSet == null)\r
                                throw new ArgumentNullException ("dataSet");\r
                        if (!IsLegalSchemaAction (missingSchemaAction))\r
                                throw new ArgumentOutOfRangeException ("missingSchemaAction");\r
-                       \r
+\r
                        MergeManager.Merge (this, dataSet, preserveChanges, missingSchemaAction);\r
                }\r
-               \r
+\r
                public void Merge (DataTable table, bool preserveChanges, MissingSchemaAction missingSchemaAction)\r
                {\r
                        if (table == null)\r
                                throw new ArgumentNullException ("table");\r
                        if (!IsLegalSchemaAction (missingSchemaAction))\r
                                throw new ArgumentOutOfRangeException ("missingSchemaAction");\r
-                       \r
+\r
                        MergeManager.Merge (this, table, preserveChanges, missingSchemaAction);\r
                }\r
 \r
@@ -323,21 +304,21 @@ namespace System.Data {
                                return true;\r
                        return false;\r
                }\r
-               \r
+\r
                [DataCategory ("Data")]\r
 #if !NET_2_0\r
                [DataSysDescription ("Indicates the XML uri namespace for the root element pointed at by this DataSet.")]\r
 #endif\r
                [DefaultValue ("")]\r
                public string Namespace {\r
-                       get { return _namespace; } \r
+                       get { return _namespace; }\r
                        set {\r
                                //TODO - trigger an event if this happens?\r
                                if (value == null)\r
                                        value = String.Empty;\r
                                 if (value != this._namespace)\r
-                                        RaisePropertyChanging ("Namespace");\r
-                               _namespace = value;\r
+                                       RaisePropertyChanging ("Namespace");\r
+                               _namespace = value;\r
                        }\r
                }\r
 \r
@@ -347,21 +328,17 @@ namespace System.Data {
 #endif\r
                [DefaultValue ("")]\r
                public string Prefix {\r
-                       get { return prefix; } \r
+                       get { return prefix; }\r
                        set {\r
                                if (value == null)\r
                                        value = String.Empty;\r
-                              // Prefix cannot contain any special characters other than '_' and ':'\r
-                               for (int i = 0; i < value.Length; i++) {\r
-                                       if (!(Char.IsLetterOrDigit (value [i])) && (value [i] != '_') && (value [i] != ':'))\r
-                                               throw new DataException ("Prefix '" + value + "' is not valid, because it contains special characters.");\r
-                               }\r
-\r
+                               // Prefix cannot contain any special characters other than '_' and ':'\r
+                               for (int i = 0; i < value.Length; i++) {\r
+                                       if (!(Char.IsLetterOrDigit (value [i])) && (value [i] != '_') && (value [i] != ':'))\r
+                                               throw new DataException ("Prefix '" + value + "' is not valid, because it contains special characters.");\r
+                               }\r
 \r
-                               if (value == null)\r
-                                       value = string.Empty;\r
-                               \r
-                               if (value != this.prefix) \r
+                               if (value != this.prefix)\r
                                        RaisePropertyChanging ("Prefix");\r
                                prefix = value;\r
                        }\r
@@ -373,21 +350,14 @@ namespace System.Data {
 #endif\r
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]\r
                public DataRelationCollection Relations {\r
-                       get {\r
-                               return relationCollection;              \r
-                       }\r
+                       get { return relationCollection; }\r
                }\r
 \r
                [Browsable (false)]\r
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]\r
                public override ISite Site {\r
-                       get {\r
-                               return base.Site;\r
-                       } \r
-                       \r
-                       set {\r
-                               base.Site = value;\r
-                       }\r
+                       get { return base.Site; }\r
+                       set { base.Site = value; }\r
                }\r
 \r
                [DataCategory ("Data")]\r
@@ -399,23 +369,6 @@ namespace System.Data {
                        get { return tableCollection; }\r
                }\r
 \r
-#if NET_2_0\r
-               [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]\r
-               [Browsable (false)]\r
-               public virtual SchemaSerializationMode SchemaSerializationMode {\r
-\r
-                       get {\r
-                               return SchemaSerializationMode.IncludeSchema;           \r
-                       }\r
-\r
-                       set {\r
-                               if (value != SchemaSerializationMode.IncludeSchema) \r
-                                       throw new InvalidOperationException (\r
-                                                       "Only IncludeSchema Mode can be set for Untyped DataSet");\r
-                       }\r
-               }\r
-#endif \r
-\r
                #endregion // Public Properties\r
 \r
                #region Public Methods\r
@@ -426,40 +379,38 @@ namespace System.Data {
                                tempTable.AcceptChanges ();\r
                }\r
 \r
-                /// <summary>\r
-                /// Clears all the tables\r
-                /// </summary>\r
+               /// <summary>\r
+               /// Clears all the tables\r
+               /// </summary>\r
                public void Clear ()\r
                {\r
                        if (_xmlDataDocument != null)\r
                                throw new NotSupportedException ("Clear function on dataset and datatable is not supported when XmlDataDocument is bound to the DataSet.");\r
-                        bool enforceConstraints = this.EnforceConstraints;\r
-                        this.EnforceConstraints = false;\r
-                        for (int t = 0; t < tableCollection.Count; t++) {\r
+                       bool enforceConstraints = this.EnforceConstraints;\r
+                       this.EnforceConstraints = false;\r
+                       for (int t = 0; t < tableCollection.Count; t++)\r
                                tableCollection[t].Clear ();\r
-                       }\r
-                        this.EnforceConstraints = enforceConstraints;\r
+                       this.EnforceConstraints = enforceConstraints;\r
                }\r
 \r
                public virtual DataSet Clone ()\r
                {\r
                        // need to return the same type as this...\r
-                       DataSet Copy = (DataSet) Activator.CreateInstance(GetType(), true);\r
-       \r
+                       DataSet Copy = (DataSet) Activator.CreateInstance (GetType (), true);\r
+\r
                        CopyProperties (Copy);\r
 \r
                        foreach (DataTable Table in Tables) {\r
-                       // tables are often added in no-args constructor, don't add them\r
-                       // twice.\r
-                               if (!Copy.Tables.Contains(Table.TableName)) {\r
-                                       Copy.Tables.Add (Table.Clone ());\r
-                               }\r
+                               // tables are often added in no-args constructor, don't add them\r
+                               // twice.\r
+                               if (!Copy.Tables.Contains (Table.TableName))\r
+                                       Copy.Tables.Add (Table.Clone ());\r
                        }\r
 \r
                        //Copy Relationships between tables after existance of tables\r
                        //and setting properties correctly\r
                        CopyRelations (Copy);\r
-                       \r
+\r
                        return Copy;\r
                }\r
 \r
@@ -467,7 +418,7 @@ namespace System.Data {
                public DataSet Copy ()\r
                {\r
                        // need to return the same type as this...\r
-                       DataSet Copy = (DataSet) Activator.CreateInstance(GetType(), true);\r
+                       DataSet Copy = (DataSet) Activator.CreateInstance (GetType (), true);\r
 \r
                        CopyProperties (Copy);\r
 \r
@@ -497,20 +448,19 @@ namespace System.Data {
                        //Copy.DesignMode\r
                        Copy.EnforceConstraints = EnforceConstraints;\r
                        if(ExtendedProperties.Count > 0) {\r
-                               //  Cannot copy extended properties directly as the property does not have a set accessor\r
-                Array tgtArray = Array.CreateInstance( typeof (object), ExtendedProperties.Count);\r
-                ExtendedProperties.Keys.CopyTo (tgtArray, 0);\r
-                for (int i=0; i < ExtendedProperties.Count; i++)\r
+                               // Cannot copy extended properties directly as the property does not have a set accessor\r
+                               Array tgtArray = Array.CreateInstance( typeof (object), ExtendedProperties.Count);\r
+                               ExtendedProperties.Keys.CopyTo (tgtArray, 0);\r
+                               for (int i = 0; i < ExtendedProperties.Count; i++)\r
                                        Copy.ExtendedProperties.Add (tgtArray.GetValue (i), ExtendedProperties[tgtArray.GetValue (i)]);\r
                        }\r
-            Copy.Locale = Locale;\r
+                       Copy.locale = locale;\r
                        Copy.Namespace = Namespace;\r
-                       Copy.Prefix = Prefix;                   \r
+                       Copy.Prefix = Prefix;\r
                        //Copy.Site = Site; // FIXME : Not sure of this.\r
-\r
                }\r
-               \r
-               \r
+\r
+\r
                private void CopyRelations (DataSet Copy)\r
                {\r
 \r
@@ -522,14 +472,14 @@ namespace System.Data {
 \r
                                // typed datasets create relations through ctor.\r
                                if (Copy.Relations.Contains (MyRelation.RelationName))\r
-                                   continue;\r
+                                       continue;\r
 \r
                                string pTable = MyRelation.ParentTable.TableName;\r
                                string cTable = MyRelation.ChildTable.TableName;\r
-                               DataColumn[] P_DC = new DataColumn[MyRelation.ParentColumns.Length]; \r
+                               DataColumn[] P_DC = new DataColumn[MyRelation.ParentColumns.Length];\r
                                DataColumn[] C_DC = new DataColumn[MyRelation.ChildColumns.Length];\r
                                int i = 0;\r
-                               \r
+\r
                                foreach (DataColumn DC in MyRelation.ParentColumns) {\r
                                        P_DC[i]=Copy.Tables[pTable].Columns[DC.ColumnName];\r
                                        i++;\r
@@ -541,16 +491,16 @@ namespace System.Data {
                                        C_DC[i]=Copy.Tables[cTable].Columns[DC.ColumnName];\r
                                        i++;\r
                                }\r
-                               \r
+\r
                                DataRelation cRel = new DataRelation (MyRelation.RelationName, P_DC, C_DC, false);\r
                                Copy.Relations.Add (cRel);\r
                        }\r
-                       \r
+\r
                        // Foreign Key constraints are not cloned in DataTable.Clone\r
                        // so, these constraints should be cloned when copying the relations.\r
                        foreach (DataTable table in this.Tables) {\r
                                foreach (Constraint c in table.Constraints) {\r
-                                       if (!(c is ForeignKeyConstraint) \r
+                                       if (!(c is ForeignKeyConstraint)\r
                                                || Copy.Tables[table.TableName].Constraints.Contains (c.ConstraintName))\r
                                                continue;\r
                                        ForeignKeyConstraint fc = (ForeignKeyConstraint)c;\r
@@ -572,12 +522,12 @@ namespace System.Data {
                        return GetChanges (DataRowState.Added | DataRowState.Deleted | DataRowState.Modified);\r
                }\r
 \r
-               \r
+\r
                public DataSet GetChanges (DataRowState rowStates)\r
                {\r
                        if (!HasChanges (rowStates))\r
                                return null;\r
-                       \r
+\r
                        DataSet copySet = Clone ();\r
                        bool prev = copySet.EnforceConstraints;\r
                        copySet.EnforceConstraints = false;\r
@@ -589,8 +539,7 @@ namespace System.Data {
                                DataTable copyTable = copySet.Tables[origTable.TableName];\r
                                for (int j = 0; j < origTable.Rows.Count; j++) {\r
                                        DataRow row = origTable.Rows [j];\r
-                                       if (!row.IsRowChanged (rowStates)\r
-                                           || addedRows.Contains (row))\r
+                                       if (!row.IsRowChanged (rowStates) || addedRows.Contains (row))\r
                                                continue;\r
                                        AddChangedRow (addedRows, copyTable, row);\r
                                }\r
@@ -598,13 +547,14 @@ namespace System.Data {
                        copySet.EnforceConstraints = prev;\r
                        return copySet;\r
                }\r
-               \r
+\r
                private void AddChangedRow (Hashtable addedRows, DataTable copyTable, DataRow row)\r
                {\r
-                       if (addedRows.ContainsKey (row)) return;\r
+                       if (addedRows.ContainsKey (row))\r
+                               return;\r
 \r
                        foreach (DataRelation relation in row.Table.ParentRelations) {\r
-                               DataRow parent = ( row.RowState != DataRowState.Deleted ? \r
+                               DataRow parent = ( row.RowState != DataRowState.Deleted ?\r
                                                   row.GetParentRow (relation) :\r
                                                   row.GetParentRow (relation, DataRowVersion.Original)\r
                                                   );\r
@@ -616,25 +566,13 @@ namespace System.Data {
                        }\r
 \r
                        // add the current row\r
-                       DataRow newRow = copyTable.NewNotInitializedRow();\r
-                       copyTable.Rows.AddInternal(newRow);\r
+                       DataRow newRow = copyTable.NewNotInitializedRow ();\r
+                       copyTable.Rows.AddInternal (newRow);\r
                        row.CopyValuesToRow (newRow);\r
                        newRow.XmlRowID = row.XmlRowID;\r
                        addedRows.Add (row, row);\r
                }\r
 \r
-#if NET_2_0\r
-               public DataTableReader CreateDataReader (params DataTable[] dataTables)\r
-               {\r
-                       return new DataTableReader (dataTables);\r
-               }\r
-\r
-               public DataTableReader CreateDataReader ()\r
-               {\r
-                       return new DataTableReader ((DataTable[])Tables.ToArray (typeof (DataTable)));\r
-               }\r
-#endif\r
-               \r
                public string GetXml ()\r
                {\r
                        StringWriter Writer = new StringWriter ();\r
@@ -649,22 +587,15 @@ namespace System.Data {
                        return Writer.ToString ();\r
                }\r
 \r
-#if NET_2_0\r
-               [MonoTODO]\r
-               public static XmlSchemaComplexType GetDataSetSchema (XmlSchemaSet schemaSet)\r
-               {\r
-                       throw new NotImplementedException ();\r
-               }\r
-#endif\r
                public bool HasChanges ()\r
                {\r
                        return HasChanges (DataRowState.Added | DataRowState.Deleted | DataRowState.Modified);\r
                }\r
 \r
-               public bool HasChanges (DataRowState rowState)\r
+               public bool HasChanges (DataRowState rowStates)\r
                {\r
-                       if (((int)rowState & 0xffffffe0) != 0)\r
-                               throw new ArgumentOutOfRangeException ("rowState");\r
+                       if (((int) rowStates & 0xffffffe0) != 0)\r
+                               throw new ArgumentOutOfRangeException ("rowStates");\r
 \r
                        DataTableCollection tableCollection = Tables;\r
                        DataTable table;\r
@@ -672,16 +603,16 @@ namespace System.Data {
                        DataRow row;\r
 \r
                        for (int i = 0; i < tableCollection.Count; i++) {\r
-                               table = tableCollection[i];\r
+                               table = tableCollection [i];\r
                                rowCollection = table.Rows;\r
                                for (int j = 0; j < rowCollection.Count; j++) {\r
-                                       row = rowCollection[j];\r
-                                       if ((row.RowState & rowState) != 0)\r
+                                       row = rowCollection [j];\r
+                                       if ((row.RowState & rowStates) != 0)\r
                                                return true;\r
                                }\r
                        }\r
 \r
-                       return false;           \r
+                       return false;\r
                }\r
 \r
                public void InferXmlSchema (XmlReader reader, string[] nsArray)\r
@@ -718,61 +649,13 @@ namespace System.Data {
                        }\r
                }\r
 \r
-#if NET_2_0\r
-               public void Load (IDataReader reader, LoadOption loadOption, params DataTable[] tables)\r
-               {\r
-                       if (reader == null) {\r
-                               throw new ArgumentNullException ("Value cannot be null. Parameter name: reader");\r
-                       }\r
-                       foreach (DataTable dt in tables) {\r
-                               if (dt.DataSet == null || dt.DataSet != this) {\r
-                                       throw new ArgumentException ("Table " +  dt.TableName + " does not belong to this DataSet.");\r
-                               }\r
-                               dt.Load (reader, loadOption);\r
-                               reader.NextResult ();\r
-                       }\r
-               }\r
-\r
-               public void Load (IDataReader reader, LoadOption loadOption, params string[] tables)\r
-               {\r
-                       if (reader == null) {\r
-                               throw new ArgumentNullException ("Value cannot be null. Parameter name: reader");\r
-                       }\r
-                       foreach (string tableName in tables) {\r
-                               DataTable dt = Tables [tableName];\r
-\r
-                               if (dt == null) {\r
-                                       dt = new DataTable (tableName);\r
-                                       Tables.Add (dt);\r
-                               }\r
-                               dt.Load (reader, loadOption);\r
-                               reader.NextResult ();\r
-                       }\r
-               }\r
-\r
-               public virtual void Load (IDataReader reader, LoadOption loadOption,\r
-                                         FillErrorEventHandler errorHandler, params DataTable[] tables)\r
-               {\r
-                       if (reader == null) {\r
-                               throw new ArgumentNullException ("Value cannot be null. Parameter name: reader");\r
-                       }\r
-                       foreach (DataTable dt in tables) {\r
-                               if (dt.DataSet == null || dt.DataSet != this) {\r
-                                       throw new ArgumentException ("Table " +  dt.TableName + " does not belong to this DataSet.");\r
-                               }\r
-                               dt.Load (reader, loadOption, errorHandler);\r
-                               reader.NextResult ();\r
-                       }\r
-               }\r
-#endif\r
-\r
                public virtual void RejectChanges ()\r
                {\r
                        int i;\r
                        bool oldEnforceConstraints = this.EnforceConstraints;\r
                        this.EnforceConstraints = false;\r
-                       \r
-                       for (i = 0; i < this.Tables.Count;i++) \r
+\r
+                       for (i = 0; i < this.Tables.Count;i++)\r
                                this.Tables[i].RejectChanges ();\r
 \r
                        this.EnforceConstraints = oldEnforceConstraints;\r
@@ -780,8 +663,6 @@ namespace System.Data {
 \r
                public virtual void Reset ()\r
                {\r
-                       IEnumerator constraintEnumerator;\r
-\r
                        // first we remove all ForeignKeyConstraints (if we will not do that\r
                        // we will get an exception when clearing the tables).\r
                        for (int i = 0; i < Tables.Count; i++) {\r
@@ -815,8 +696,7 @@ namespace System.Data {
                        writer.WriteStartDocument (true);\r
                        try {\r
                                WriteXml (writer);\r
-                       }\r
-                       finally {\r
+                       } finally {\r
                                writer.WriteEndDocument ();\r
                                writer.Close ();\r
                        }\r
@@ -834,16 +714,15 @@ namespace System.Data {
                        WriteXml (writer, XmlWriteMode.IgnoreSchema);\r
                }\r
 \r
-               public void WriteXml (string filename, XmlWriteMode mode)\r
+               public void WriteXml (string fileName, XmlWriteMode mode)\r
                {\r
-                       XmlTextWriter writer = new XmlTextWriter (filename, null);\r
+                       XmlTextWriter writer = new XmlTextWriter (fileName, null);\r
                        writer.Formatting = Formatting.Indented;\r
                        writer.WriteStartDocument (true);\r
-                       \r
+\r
                        try {\r
                                WriteXml (writer, mode);\r
-                       }\r
-                       finally {\r
+                       } finally {\r
                                writer.WriteEndDocument ();\r
                                writer.Close ();\r
                        }\r
@@ -869,32 +748,31 @@ namespace System.Data {
                                SetRowsID();\r
                                WriteDiffGramElement(writer);\r
                        }\r
-                       \r
+\r
                        // It should not write when there is no content to be written\r
                        bool shouldOutputContent = (mode != XmlWriteMode.DiffGram);\r
                        for (int n = 0; n < tableCollection.Count && !shouldOutputContent; n++)\r
                                shouldOutputContent = tableCollection [n].Rows.Count > 0;\r
-                               \r
+\r
                        if (shouldOutputContent) {\r
                                WriteStartElement (writer, mode, Namespace, Prefix, XmlHelper.Encode (DataSetName));\r
-                               \r
+\r
                                if (mode == XmlWriteMode.WriteSchema)\r
                                        DoWriteXmlSchema (writer);\r
-                               \r
+\r
                                WriteTables (writer, mode, Tables, DataRowVersion.Default);\r
                                writer.WriteEndElement ();\r
                        }\r
-                       \r
+\r
                        if (mode == XmlWriteMode.DiffGram) {\r
                                if (HasChanges(DataRowState.Modified | DataRowState.Deleted)) {\r
-\r
                                        DataSet beforeDS = GetChanges (DataRowState.Modified | DataRowState.Deleted);\r
                                        WriteStartElement (writer, XmlWriteMode.DiffGram, XmlConstants.DiffgrNamespace, XmlConstants.DiffgrPrefix, "before");\r
                                        WriteTables (writer, mode, beforeDS.Tables, DataRowVersion.Original);\r
                                        writer.WriteEndElement ();\r
                                }\r
                        }\r
-                       \r
+\r
                        if (mode == XmlWriteMode.DiffGram)\r
                                writer.WriteEndElement (); // diffgr:diffgram\r
 \r
@@ -905,7 +783,7 @@ namespace System.Data {
                {\r
                        XmlTextWriter writer = new XmlTextWriter (stream, null );\r
                        writer.Formatting = Formatting.Indented;\r
-                       WriteXmlSchema (writer);        \r
+                       WriteXmlSchema (writer);\r
                }\r
 \r
                public void WriteXmlSchema (string fileName)\r
@@ -934,7 +812,7 @@ namespace System.Data {
 \r
                public void WriteXmlSchema (XmlWriter writer)\r
                {\r
-                       //Create a skeleton doc and then write the schema \r
+                       //Create a skeleton doc and then write the schema\r
                        //proper which is common to the WriteXml method in schema mode\r
                        DoWriteXmlSchema (writer);\r
                }\r
@@ -945,27 +823,30 @@ namespace System.Data {
                        ReadXmlSchema (reader);\r
                }\r
 \r
-               public void ReadXmlSchema (string str)\r
+               public void ReadXmlSchema (string fileName)\r
                {\r
-                       XmlReader reader = new XmlTextReader (str);\r
+                       XmlReader reader = new XmlTextReader (fileName);\r
                        try {\r
                                ReadXmlSchema (reader);\r
-                       }\r
-                       finally {\r
+                       } finally {\r
                                reader.Close ();\r
                        }\r
                }\r
 \r
-               public void ReadXmlSchema (TextReader treader)\r
+               public void ReadXmlSchema (TextReader reader)\r
                {\r
-                       XmlReader reader = new XmlTextReader (treader);\r
-                       ReadXmlSchema (reader);                 \r
+                       XmlReader xr = new XmlTextReader (reader);\r
+                       ReadXmlSchema (xr);\r
                }\r
 \r
                public void ReadXmlSchema (XmlReader reader)\r
                {\r
 #if true\r
-                       new XmlSchemaDataImporter (this, reader).Process ();\r
+                       XmlSchemaDataImporter xsdImporter = new XmlSchemaDataImporter (this, reader, true);\r
+                       xsdImporter.Process ();\r
+#if NET_2_0\r
+                       tableAdapterSchemaInfo = xsdImporter.CurrentAdapter;\r
+#endif\r
 #else\r
                        XmlSchemaMapper SchemaMapper = new XmlSchemaMapper (this);\r
                        SchemaMapper.Read (reader);\r
@@ -977,13 +858,12 @@ namespace System.Data {
                        return ReadXml (new XmlTextReader (stream));\r
                }\r
 \r
-               public XmlReadMode ReadXml (string str)\r
+               public XmlReadMode ReadXml (string fileName)\r
                {\r
-                       XmlTextReader reader = new XmlTextReader (str);\r
+                       XmlTextReader reader = new XmlTextReader (fileName);\r
                        try {\r
                                return ReadXml (reader);\r
-                       }\r
-                       finally {\r
+                       } finally {\r
                                reader.Close ();\r
                        }\r
                }\r
@@ -993,9 +873,9 @@ namespace System.Data {
                        return ReadXml (new XmlTextReader (reader));\r
                }\r
 \r
-               public XmlReadMode ReadXml (XmlReader r)\r
+               public XmlReadMode ReadXml (XmlReader reader)\r
                {\r
-                       return ReadXml (r, XmlReadMode.Auto);\r
+                       return ReadXml (reader, XmlReadMode.Auto);\r
                }\r
 \r
                public XmlReadMode ReadXml (Stream stream, XmlReadMode mode)\r
@@ -1003,13 +883,12 @@ namespace System.Data {
                        return ReadXml (new XmlTextReader (stream), mode);\r
                }\r
 \r
-               public XmlReadMode ReadXml (string str, XmlReadMode mode)\r
+               public XmlReadMode ReadXml (string fileName, XmlReadMode mode)\r
                {\r
-                       XmlTextReader reader = new XmlTextReader (str);\r
+                       XmlTextReader reader = new XmlTextReader (fileName);\r
                        try {\r
                                return ReadXml (reader, mode);\r
-                       }\r
-                       finally {\r
+                       } finally {\r
                                reader.Close ();\r
                        }\r
                }\r
@@ -1042,10 +921,9 @@ namespace System.Data {
                                ((XmlTextReader) reader).WhitespaceHandling = WhitespaceHandling.None;\r
                        }\r
 \r
-                       XmlReadMode Result = mode;\r
                        XmlDiffLoader DiffLoader = null;\r
 \r
-                       // If diffgram, then read the first element as diffgram \r
+                       // If diffgram, then read the first element as diffgram\r
                        if (reader.LocalName == "diffgram" && reader.NamespaceURI == XmlConstants.DiffgrNamespace) {\r
                                switch (mode) {\r
                                        case XmlReadMode.Auto:\r
@@ -1054,7 +932,7 @@ namespace System.Data {
                                                        DiffLoader = new XmlDiffLoader (this);\r
                                                DiffLoader.Load (reader);\r
                                                // (and leave rest of the reader as is)\r
-                                               return  XmlReadMode.DiffGram;\r
+                                               return XmlReadMode.DiffGram;\r
                                        case XmlReadMode.Fragment:\r
                                                reader.Skip ();\r
                                                // (and continue to read)\r
@@ -1066,7 +944,7 @@ namespace System.Data {
                                }\r
                        }\r
 \r
-                       // If schema, then read the first element as schema \r
+                       // If schema, then read the first element as schema\r
                        if (reader.LocalName == "schema" && reader.NamespaceURI == XmlSchema.Namespace) {\r
                                switch (mode) {\r
                                        case XmlReadMode.IgnoreSchema:\r
@@ -1135,7 +1013,7 @@ namespace System.Data {
                                                case XmlReadMode.InferSchema:\r
                                                        reader.Skip ();\r
                                                        break;\r
-                                               \r
+\r
                                                default:\r
                                                        ReadXmlSchema (reader);\r
                                                        retMode = XmlReadMode.ReadSchema;\r
@@ -1146,7 +1024,7 @@ namespace System.Data {
 \r
                                        continue;\r
                                }\r
-       \r
+\r
                                if ((reader.LocalName == "diffgram") && (reader.NamespaceURI == XmlConstants.DiffgrNamespace)) {\r
                                        if ((mode == XmlReadMode.DiffGram) || (mode == XmlReadMode.IgnoreSchema)\r
                                                || mode == XmlReadMode.Auto) {\r
@@ -1181,7 +1059,7 @@ namespace System.Data {
                                retMode != XmlReadMode.ReadSchema &&\r
                                mode != XmlReadMode.IgnoreSchema &&\r
                                mode != XmlReadMode.Fragment &&\r
-                               Tables.Count == 0) {\r
+                               (Tables.Count == 0 || mode == XmlReadMode.InferSchema)) {\r
                                InferXmlSchema(doc, null);\r
                                if (mode == XmlReadMode.Auto)\r
                                        retMode = XmlReadMode.InferSchema;\r
@@ -1203,10 +1081,6 @@ namespace System.Data {
 #endif\r
                public event MergeFailedEventHandler MergeFailed;\r
 \r
-#if NET_2_0\r
-               public event EventHandler Initialized;\r
-#endif\r
-\r
                #endregion // Public Events\r
 \r
                #region IListSource methods\r
@@ -1214,14 +1088,14 @@ namespace System.Data {
                {\r
                        return DefaultViewManager;\r
                }\r
-               \r
+\r
                bool IListSource.ContainsListCollection {\r
                        get {\r
                                return true;\r
                        }\r
                }\r
                #endregion IListSource methods\r
-               \r
+\r
                #region ISupportInitialize methods\r
 \r
                internal bool InitInProgress {\r
@@ -1236,7 +1110,7 @@ namespace System.Data {
                        dataSetInitialized = false;\r
 #endif\r
                }\r
-               \r
+\r
                public void EndInit ()\r
                {\r
                        // Finsh the init'ing the tables only after adding all the\r
@@ -1257,204 +1131,54 @@ namespace System.Data {
                }\r
                #endregion\r
 \r
+               #region ISerializable\r
 #if NET_2_0\r
-               void BinarySerialize (SerializationInfo si)\r
-               {\r
-                       Version vr = new Version(2, 0);\r
-                       si.AddValue ("DataSet.RemotingVersion", vr, typeof (Version));\r
-                       si.AddValue ("DataSet.RemotingFormat", RemotingFormat, typeof (SerializationFormat));\r
-                       si.AddValue ("DataSet.DataSetName", DataSetName);\r
-                       si.AddValue ("DataSet.Namespace", Namespace);\r
-                       si.AddValue ("DataSet.Prefix", Prefix);\r
-                       si.AddValue ("DataSet.CaseSensitive", CaseSensitive);\r
-                       si.AddValue ("DataSet.LocaleLCID", Locale.LCID);\r
-                       si.AddValue ("DataSet.EnforceConstraints", EnforceConstraints);\r
-                       si.AddValue ("DataSet.ExtendedProperties", properties, typeof (PropertyCollection));\r
-                       si.AddValue ("DataSet.Tables.Count", Tables.Count);\r
-                       for (int i = 0; i < Tables.Count; i++) {\r
-                               DataTable dt = Tables[i];\r
-                               MemoryStream ms = new MemoryStream ();\r
-                               BinaryFormatter bf = new BinaryFormatter ();\r
-                               bf.Serialize (ms, dt);\r
-                               byte [] serializedStream = ms.ToArray ();\r
-                               ms.Close ();\r
-                               si.AddValue ("DataSet.Tables_" + i, serializedStream, typeof (Byte[]));\r
-                               for (int j = 0; j < dt.Columns.Count; j++) {\r
-                                       si.AddValue ("DataTable_" + i + ".DataColumn_" + j + ".Expression",\r
-                                                    dt.Columns[j].Expression);\r
-                               }\r
-                               dt.dataSet = this;\r
-                               dt.BinarySerialize (si, "DataTable_" + i + ".");\r
-                       }\r
-                       ArrayList relationList = new ArrayList ();\r
-                       for (int j = 0; j < Relations.Count; j++)\r
-                       {\r
-                               DataRelation dr = Relations[j];\r
-                               ArrayList tmpArrayList = new ArrayList ();\r
-                               tmpArrayList.Add (dr.RelationName);\r
-                               Array relationArray = new int [2];\r
-                               DataTable dt = dr.ParentTable;\r
-                               relationArray.SetValue (Tables.IndexOf (dt), 0);\r
-                               relationArray.SetValue (dt.Columns.IndexOf (Relations[j].ParentColumns [0]), 1);\r
-                               tmpArrayList.Add (relationArray);\r
-                               relationArray = new int [2];\r
-                               dt = dr.ChildTable;\r
-                               relationArray.SetValue (Tables.IndexOf (dt), 0);\r
-                               relationArray.SetValue (dt.Columns.IndexOf (Relations [j].ChildColumns [0]), 1);\r
-                               tmpArrayList.Add (relationArray);\r
-                               tmpArrayList.Add (false); // FIXME\r
-                               tmpArrayList.Add (null); // FIXME\r
-                               relationList.Add (tmpArrayList);\r
-                       }\r
-                       si.AddValue ("DataSet.Relations", relationList, typeof (ArrayList));\r
-               }\r
-#endif\r
-\r
-               #region ISerializable\r
-#if NET_2_0\r
-               public virtual\r
-#endif\r
-               void\r
-#if !NET_2_0\r
-               ISerializable.\r
-#endif\r
-               GetObjectData (SerializationInfo si, StreamingContext sc)\r
+               public virtual\r
+#endif\r
+               void\r
+#if !NET_2_0\r
+               ISerializable.\r
+#endif\r
+               GetObjectData (SerializationInfo info, StreamingContext context)\r
                {\r
 #if NET_2_0\r
                        if (RemotingFormat == SerializationFormat.Xml) {\r
+                               info.AddValue ("SchemaSerializationMode.DataSet", this.SchemaSerializationMode);\r
 #endif\r
                                StringWriter sw = new StringWriter ();\r
                                XmlTextWriter writer = new XmlTextWriter (sw);\r
                                DoWriteXmlSchema (writer);\r
                                writer.Flush ();\r
-                               si.AddValue ("XmlSchema", sw.ToString ());\r
-                       \r
+                               info.AddValue ("XmlSchema", sw.ToString ());\r
+\r
                                sw = new StringWriter ();\r
                                writer = new XmlTextWriter (sw);\r
                                WriteXml (writer, XmlWriteMode.DiffGram);\r
                                writer.Flush ();\r
-                               si.AddValue ("XmlDiffGram", sw.ToString ());\r
+                               info.AddValue ("XmlDiffGram", sw.ToString ());\r
 #if NET_2_0\r
                        } else /*if (DataSet.RemotingFormat == SerializationFormat.Binary)*/ {\r
-                               BinarySerialize (si);\r
+                               BinarySerialize (info);\r
                        }\r
 #endif\r
                }\r
                #endregion\r
 \r
-#if NET_2_0\r
-               void BinaryDeserialize (SerializationInfo info)\r
-               {\r
-                       ArrayList arrayList = null;\r
-\r
-                       DataSetName = info.GetString ("DataSet.DataSetName");\r
-                       Namespace = info.GetString ("DataSet.Namespace");\r
-                       CaseSensitive = info.GetBoolean ("DataSet.CaseSensitive");\r
-                       Locale = new CultureInfo (info.GetInt32 ("DataSet.LocaleLCID"));\r
-                       EnforceConstraints = info.GetBoolean ("DataSet.EnforceConstraints");\r
-                       Prefix = info.GetString ("DataSet.Prefix");\r
-                       /*\r
-                         FIXME: Private variable available in SerializationInfo\r
-                         this.RemotingVersion = (System.Version) info.GetValue("DataSet.RemotingVersion",\r
-                         typeof(System.Version));\r
-                       */\r
-                       properties = (PropertyCollection) info.GetValue ("DataSet.ExtendedProperties",\r
-                                                                        typeof (PropertyCollection));\r
-                       int tableCount = info.GetInt32 ("DataSet.Tables.Count");\r
-\r
-                       Byte [] bytes;\r
-                       DataTable dt = null;\r
-                       for (int i = 0; i < tableCount; i++) {\r
-                               bytes = (Byte []) info.GetValue ("DataSet.Tables_" + i,\r
-                                                                typeof (Byte[]));\r
-                               MemoryStream ms = new MemoryStream (bytes);\r
-                               BinaryFormatter bf = new BinaryFormatter ();\r
-                               dt = (DataTable) bf.Deserialize (ms);\r
-                               ms.Close ();\r
-                               for (int j = 0; j < dt.Columns.Count; j++) {\r
-                                       dt.Columns[j].Expression = info.GetString ("DataTable_" + i +\r
-                                                                                  ".DataColumn_" + j +\r
-                                                                                  ".Expression");\r
-                               }\r
-                               /*\r
-                                 Not using\r
-                                 int rowsCount = info.GetInt32 ("DataTable_" + i + ".Rows.Count");\r
-                                 int recordsCount = info.GetInt32 ("DataTable_" + i + ".Records.Count");\r
-                               */\r
-                               ArrayList nullBits = (ArrayList) info.GetValue ("DataTable_" + i + ".NullBits",\r
-                                                                               typeof (ArrayList));\r
-                               arrayList = (ArrayList) info.GetValue ("DataTable_" + i + ".Records",\r
-                                                                      typeof (ArrayList));\r
-                               BitArray rowStateBitArray = (BitArray) info.GetValue ("DataTable_" + i + ".RowStates",\r
-                                                                                     typeof (BitArray));\r
-                               dt.DeserializeRecords (arrayList, nullBits, rowStateBitArray);\r
-                               Tables.Add (dt);\r
-                       }\r
-                       for (int i = 0; i < tableCount; i++) {\r
-                               dt = Tables [i];\r
-                               dt.dataSet = this;\r
-                               arrayList = (ArrayList) info.GetValue ("DataTable_" + i + ".Constraints",\r
-                                                                      typeof (ArrayList));\r
-                               if (dt.Constraints == null)\r
-                                       dt.Constraints = new ConstraintCollection (dt);\r
-                               dt.DeserializeConstraints (arrayList);\r
-                       }\r
-                       arrayList = (ArrayList) info.GetValue ("DataSet.Relations",\r
-                                                              typeof (ArrayList));\r
-                       bool bParentColumn = true;\r
-                       for (int l = 0; l < arrayList.Count; l++) {\r
-                               ArrayList tmpArrayList = (ArrayList) arrayList[l];\r
-                               ArrayList childColumns = new ArrayList ();\r
-                               ArrayList parentColumns = new ArrayList ();\r
-                               for (int k = 0; k < tmpArrayList.Count; k++) {\r
-                                       if (tmpArrayList[k] != null && typeof (int) == tmpArrayList[k].GetType().GetElementType()) {\r
-                                               Array dataColumnArray = (Array)tmpArrayList[k];\r
-                                               if (bParentColumn) {\r
-                                                       parentColumns.Add (Tables [(int) dataColumnArray.GetValue (0)].\r
-                                                                          Columns [(int) dataColumnArray.GetValue (1)]);\r
-                                                       bParentColumn = false;\r
-                                               }\r
-                                               else {\r
-                                                       childColumns.Add (Tables [(int) dataColumnArray.GetValue (0)].\r
-                                                                         Columns [(int) dataColumnArray.GetValue (1)]);\r
-                                                       bParentColumn = true;\r
-                                               }\r
-                                       }\r
-                               }\r
-                               Relations.Add ((string) tmpArrayList [0],\r
-                                              (DataColumn []) parentColumns.ToArray (typeof (DataColumn)),\r
-                                              (DataColumn []) childColumns.ToArray (typeof (DataColumn)),\r
-                                              false);\r
-                       }\r
-               }\r
-#endif\r
-               \r
                #region Protected Methods\r
                protected void GetSerializationData (SerializationInfo info, StreamingContext context)\r
                {\r
-#if NET_2_0\r
-                       if (IsBinarySerialized (info, context)) {\r
-                               BinaryDeserialize (info);\r
-                               return;\r
-                       }\r
-#endif\r
-                       string s = info.GetValue ("XmlSchema", typeof (String)) as String;\r
+                       string s = info.GetValue ("XmlDiffGram", typeof (String)) as String;\r
                        XmlTextReader reader = new XmlTextReader (new StringReader (s));\r
-                       ReadXmlSchema (reader);\r
-                       reader.Close ();\r
-\r
-                       s = info.GetValue ("XmlDiffGram", typeof (String)) as String;\r
-                       reader = new XmlTextReader (new StringReader (s));\r
                        ReadXml (reader, XmlReadMode.DiffGram);\r
                        reader.Close ();\r
                }\r
-               \r
-               \r
+\r
+\r
                protected virtual System.Xml.Schema.XmlSchema GetSchemaSerializable ()\r
                {\r
                        return null;\r
                }\r
-               \r
+\r
                protected virtual void ReadXmlSerializable (XmlReader reader)\r
                {\r
                        ReadXml (reader, XmlReadMode.DiffGram);\r
@@ -1464,7 +1188,7 @@ namespace System.Data {
                {\r
                        ReadXmlSerializable(reader);\r
                }\r
-               \r
+\r
                void IXmlSerializable.WriteXml (XmlWriter writer)\r
                {\r
                        DoWriteXmlSchema (writer);\r
@@ -1482,39 +1206,16 @@ namespace System.Data {
                        return XmlSchema.Read(new XmlTextReader(stream), (ValidationEventHandler)null);\r
                }\r
 \r
-#if NET_2_0\r
-               private void OnDataSetInitialized (EventArgs e) {\r
-                       if (null != Initialized) {\r
-                               Initialized (this, e);\r
-                       }\r
-               }\r
-#endif\r
-\r
                protected virtual bool ShouldSerializeRelations ()\r
                {\r
                        return true;\r
                }\r
-               \r
+\r
                protected virtual bool ShouldSerializeTables ()\r
                {\r
                        return true;\r
                }\r
 \r
-#if NET_2_0\r
-               private void DataSetInitialized ()\r
-               {\r
-                       EventArgs e = new EventArgs ();\r
-                       OnDataSetInitialized (e);\r
-               }\r
-\r
-               [MonoTODO]\r
-               protected virtual void InitializeDerivedDataSet ()\r
-               {\r
-                       throw new NotImplementedException ();\r
-               }\r
-\r
-#endif\r
-\r
                [MonoTODO]\r
                protected internal virtual void OnPropertyChanging (PropertyChangedEventArgs pcevent)\r
                {\r
@@ -1546,28 +1247,6 @@ namespace System.Data {
                {\r
                }\r
 \r
-#if NET_2_0\r
-               protected SchemaSerializationMode DetermineSchemaSerializationMode (XmlReader reader)\r
-               {\r
-                       return SchemaSerializationMode.IncludeSchema;\r
-               }\r
-\r
-               protected SchemaSerializationMode DetermineSchemaSerializationMode (SerializationInfo info, StreamingContext context)\r
-               {\r
-                       return SchemaSerializationMode.IncludeSchema;\r
-               }\r
-\r
-               protected bool IsBinarySerialized (SerializationInfo info, StreamingContext context)\r
-               {\r
-                       SerializationInfoEnumerator e = info.GetEnumerator ();\r
-                       while (e.MoveNext()) {\r
-                               if (e.ObjectType == typeof(System.Data.SerializationFormat)) {\r
-                                       return true;\r
-                               }\r
-                       }\r
-                       return false;\r
-               }\r
-#endif\r
                #endregion\r
 \r
                #region Private Methods\r
@@ -1611,12 +1290,13 @@ namespace System.Data {
                        if (o is TimeSpan) return XmlConvert.ToString ((TimeSpan) o);\r
                        if (o is Guid) return XmlConvert.ToString ((Guid) o);\r
                        if (o is byte[]) return Convert.ToBase64String ((byte[])o);\r
+\r
                        return o.ToString ();\r
                }\r
-               \r
+\r
                private void WriteTables (XmlWriter writer, XmlWriteMode mode, DataTableCollection tableCollection, DataRowVersion version)\r
                {\r
-                       //WriteTable takes care of skipping a table if it has a \r
+                       //WriteTable takes care of skipping a table if it has a\r
                        //Nested Parent Relationship\r
                        foreach (DataTable table in tableCollection)\r
                                WriteTable ( writer, table, mode, version);\r
@@ -1648,9 +1328,7 @@ namespace System.Data {
 \r
                        SplitColumns (table, out atts, out elements, out simple);\r
                        //sort out the namespacing\r
-                       string nspc = (table.Namespace.Length > 0 || table.DataSet == null) ? table.Namespace : table.DataSet.Namespace;\r
                        int relationCount = table.ParentRelations.Count;\r
-                       DataRelation oneRel = relationCount == 1 ? table.ParentRelations [0] : null;\r
 \r
                        foreach (DataRow row in rows) {\r
                                if (skipIfNested) {\r
@@ -1669,19 +1347,18 @@ namespace System.Data {
                                                continue;\r
                                }\r
 \r
-                               if (!row.HasVersion(version) || \r
-                                  (mode == XmlWriteMode.DiffGram && row.RowState == DataRowState.Unchanged \r
+                               if (!row.HasVersion(version) ||\r
+                                  (mode == XmlWriteMode.DiffGram && row.RowState == DataRowState.Unchanged\r
                                      && version == DataRowVersion.Original))\r
                                        continue;\r
-                               \r
+\r
                                // First check are all the rows null. If they are we just write empty element\r
                                bool AllNulls = true;\r
                                foreach (DataColumn dc in table.Columns) {\r
-                               \r
                                        if (row [dc.ColumnName, version] != DBNull.Value) {\r
                                                AllNulls = false;\r
                                                break;\r
-                                       } \r
+                                       }\r
                                }\r
 \r
                                // If all of the columns were null, we have to write empty element\r
@@ -1689,28 +1366,24 @@ namespace System.Data {
                                        writer.WriteElementString (XmlHelper.Encode (table.TableName), "");\r
                                        continue;\r
                                }\r
-                               \r
+\r
                                WriteTableElement (writer, mode, table, row, version);\r
-                               \r
-                               foreach (DataColumn col in atts) {                                      \r
+\r
+                               foreach (DataColumn col in atts)\r
                                        WriteColumnAsAttribute (writer, mode, col, row, version);\r
-                               }\r
-                               \r
+\r
                                if (simple != null) {\r
                                        writer.WriteString (WriteObjectXml (row[simple, version]));\r
-                               }\r
-                               else {                                  \r
-                                       foreach (DataColumn col in elements) {\r
+                               } else {\r
+                                       foreach (DataColumn col in elements)\r
                                                WriteColumnAsElement (writer, mode, col, row, version);\r
-                                       }\r
                                }\r
-                               \r
+\r
                                foreach (DataRelation relation in table.ChildRelations) {\r
-                                       if (relation.Nested) {\r
+                                       if (relation.Nested)\r
                                                WriteTable (writer, row.GetChildRows (relation), mode, version, false);\r
-                                       }\r
                                }\r
-                               \r
+\r
                                writer.WriteEndElement ();\r
                        }\r
 \r
@@ -1720,16 +1393,25 @@ namespace System.Data {
                {\r
                        string colnspc = null;\r
                        object rowObject = row [col, version];\r
-                                                                       \r
+\r
                        if (rowObject == null || rowObject == DBNull.Value)\r
                                return;\r
 \r
                        if (col.Namespace != String.Empty)\r
                                colnspc = col.Namespace;\r
-       \r
+\r
                        //TODO check if I can get away with write element string\r
-                       WriteStartElement (writer, mode, colnspc, col.Prefix, XmlHelper.Encode (col.ColumnName));\r
-                       writer.WriteString (WriteObjectXml (rowObject));\r
+                       WriteStartElement (writer, mode, colnspc, col.Prefix, XmlHelper.Encode (col.ColumnName));       \r
+                       if (typeof (IXmlSerializable).IsAssignableFrom (col.DataType) \r
+                           || col.DataType == typeof (object)) {\r
+                               IXmlSerializable serializableObj = rowObject as IXmlSerializable;\r
+                               if (serializableObj == null)\r
+                                       throw new InvalidOperationException ();\r
+                               ((IXmlSerializable)rowObject).WriteXml (writer);                                \r
+                       } else {\r
+                               writer.WriteString (WriteObjectXml (rowObject));\r
+                       }\r
+\r
                        writer.WriteEndElement ();\r
                }\r
 \r
@@ -1759,43 +1441,43 @@ namespace System.Data {
                                        WriteAttributeString (writer, mode, XmlConstants.DiffgrNamespace, XmlConstants.DiffgrPrefix, "hasChanges", modeName);\r
                        }\r
                }\r
-                   \r
+\r
                internal static void WriteStartElement (XmlWriter writer, XmlWriteMode mode, string nspc, string prefix, string name)\r
                {\r
                        writer.WriteStartElement (prefix, name, nspc);\r
                }\r
-               \r
+\r
                internal static void WriteAttributeString (XmlWriter writer, XmlWriteMode mode, string nspc, string prefix, string name, string stringValue)\r
                {\r
                        switch ( mode) {\r
-                               case XmlWriteMode.WriteSchema:\r
-                                       writer.WriteAttributeString (prefix, name, nspc);\r
-                                       break;\r
+                       //      case XmlWriteMode.WriteSchema:\r
+                       //              writer.WriteAttributeString (prefix, name, nspc);\r
+                       //              break;\r
                                case XmlWriteMode.DiffGram:\r
                                        writer.WriteAttributeString (prefix, name, nspc,stringValue);\r
                                        break;\r
                                default:\r
                                        writer.WriteAttributeString (name, stringValue);\r
-                                       break;                                  \r
+                                       break;\r
                        };\r
                }\r
-               \r
+\r
                internal void WriteIndividualTableContent (XmlWriter writer, DataTable table, XmlWriteMode mode)\r
                {\r
                        if (mode == XmlWriteMode.DiffGram) {\r
                                table.SetRowsID ();\r
                                WriteDiffGramElement (writer);\r
                        }\r
-                       \r
+\r
                        WriteStartElement (writer, mode, Namespace, Prefix, XmlHelper.Encode (DataSetName));\r
-                       \r
+\r
                        WriteTable (writer, table, mode, DataRowVersion.Default);\r
-                       \r
+\r
                        if (mode == XmlWriteMode.DiffGram) {\r
                                writer.WriteEndElement (); //DataSet name\r
                                if (HasChanges (DataRowState.Modified | DataRowState.Deleted)) {\r
 \r
-                                       DataSet beforeDS = GetChanges (DataRowState.Modified | DataRowState.Deleted);   \r
+                                       DataSet beforeDS = GetChanges (DataRowState.Modified | DataRowState.Deleted);\r
                                        WriteStartElement (writer, XmlWriteMode.DiffGram, XmlConstants.DiffgrNamespace, XmlConstants.DiffgrPrefix, "before");\r
                                        WriteTable (writer, beforeDS.Tables [table.TableName], mode, DataRowVersion.Original);\r
                                        writer.WriteEndElement ();\r
@@ -1803,21 +1485,21 @@ namespace System.Data {
                        }\r
                        writer.WriteEndElement (); // DataSet name or diffgr:diffgram\r
                }\r
-               \r
+\r
                private void DoWriteXmlSchema (XmlWriter writer)\r
                {\r
                        if (writer.WriteState == WriteState.Start)\r
                                writer.WriteStartDocument ();\r
                        XmlSchemaWriter.WriteXmlSchema (this, writer);\r
                }\r
-               \r
+\r
                ///<summary>\r
                /// Helper function to split columns into attributes elements and simple\r
                /// content\r
                /// </summary>\r
-               internal static void SplitColumns (DataTable table, \r
-                       out ArrayList atts, \r
-                       out ArrayList elements, \r
+               internal static void SplitColumns (DataTable table,\r
+                       out ArrayList atts,\r
+                       out ArrayList elements,\r
                        out DataColumn simple)\r
                {\r
                        //The columns can be attributes, hidden, elements, or simple content\r
@@ -1825,7 +1507,7 @@ namespace System.Data {
                        atts = new System.Collections.ArrayList ();\r
                        elements = new System.Collections.ArrayList ();\r
                        simple = null;\r
-                       \r
+\r
                        //Sort out the columns\r
                        foreach (DataColumn col in table.Columns) {\r
                                switch (col.ColumnMapping) {\r
@@ -1848,18 +1530,278 @@ namespace System.Data {
                        }\r
                }\r
 \r
-               internal static void WriteDiffGramElement(XmlWriter writer)\r
+               internal static void WriteDiffGramElement (XmlWriter writer)\r
                {\r
                        WriteStartElement (writer, XmlWriteMode.DiffGram, XmlConstants.DiffgrNamespace, XmlConstants.DiffgrPrefix, "diffgram");\r
-                       WriteAttributeString(writer, XmlWriteMode.DiffGram, null, "xmlns", XmlConstants.MsdataPrefix, XmlConstants.MsdataNamespace);\r
+                       WriteAttributeString (writer, XmlWriteMode.DiffGram, null, "xmlns", XmlConstants.MsdataPrefix, XmlConstants.MsdataNamespace);\r
                }\r
 \r
-               private void SetRowsID()\r
+               private void SetRowsID ()\r
                {\r
                        foreach (DataTable table in Tables)\r
-                               table.SetRowsID();\r
+                               table.SetRowsID ();\r
                }\r
-               \r
+\r
                #endregion //Private Xml Serialisation\r
        }\r
+\r
+#if NET_2_0\r
+       [XmlSchemaProvider ("GetDataSetSchema")]\r
+       [XmlRoot ("DataSet")]\r
+       partial class DataSet : ISupportInitializeNotification {\r
+               private bool dataSetInitialized = true;\r
+               public event EventHandler Initialized;\r
+\r
+               protected DataSet (SerializationInfo info, StreamingContext context, bool constructSchema)\r
+                       : this ()\r
+               {\r
+                       if (DetermineSchemaSerializationMode (info, context) == SchemaSerializationMode.ExcludeSchema) {\r
+                               InitializeDerivedDataSet ();\r
+                       }\r
+                       \r
+                       if (IsBinarySerialized (info, context)) {\r
+                               BinaryDeserialize (info);\r
+                               return;\r
+                       }\r
+                       \r
+                       if (constructSchema) {\r
+                               string s = info.GetValue ("XmlSchema", typeof (String)) as String;\r
+                               XmlTextReader reader = new XmlTextReader (new StringReader (s));\r
+                               ReadXmlSchema (reader);\r
+                               reader.Close ();\r
+                               \r
+                               GetSerializationData (info, context);\r
+                       }\r
+               }\r
+\r
+               SerializationFormat remotingFormat = SerializationFormat.Xml;\r
+               [DefaultValue (SerializationFormat.Xml)]\r
+               public SerializationFormat RemotingFormat {\r
+                       get { return remotingFormat; }\r
+                       set { remotingFormat = value; }\r
+               }\r
+\r
+               [Browsable (false)]\r
+               public bool IsInitialized {\r
+                       get { return dataSetInitialized; }\r
+               }\r
+\r
+               [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]\r
+               [Browsable (false)]\r
+               public virtual SchemaSerializationMode SchemaSerializationMode {\r
+                       get { return SchemaSerializationMode.IncludeSchema; }\r
+                       set {\r
+                               if (value != SchemaSerializationMode.IncludeSchema)\r
+                                       throw new InvalidOperationException (\r
+                                                       "Only IncludeSchema Mode can be set for Untyped DataSet");\r
+                       }\r
+               }\r
+\r
+               public DataTableReader CreateDataReader (params DataTable[] dataTables)\r
+               {\r
+                       return new DataTableReader (dataTables);\r
+               }\r
+\r
+               public DataTableReader CreateDataReader ()\r
+               {\r
+                       return new DataTableReader ((DataTable[])Tables.ToArray (typeof (DataTable)));\r
+               }\r
+\r
+               public static XmlSchemaComplexType GetDataSetSchema (XmlSchemaSet schemaSet)\r
+               {\r
+                       return new XmlSchemaComplexType ();\r
+               }\r
+\r
+               public void Load (IDataReader reader, LoadOption loadOption, params DataTable[] tables)\r
+               {\r
+                       if (reader == null)\r
+                               throw new ArgumentNullException ("Value cannot be null. Parameter name: reader");\r
+\r
+                       foreach (DataTable dt in tables) {\r
+                               if (dt.DataSet == null || dt.DataSet != this)\r
+                                       throw new ArgumentException ("Table " + dt.TableName + " does not belong to this DataSet.");\r
+                               dt.Load (reader, loadOption);\r
+                               reader.NextResult ();\r
+                       }\r
+               }\r
+\r
+               public void Load (IDataReader reader, LoadOption loadOption, params string[] tables)\r
+               {\r
+                       if (reader == null)\r
+                               throw new ArgumentNullException ("Value cannot be null. Parameter name: reader");\r
+\r
+                       foreach (string tableName in tables) {\r
+                               DataTable dt = Tables [tableName];\r
+\r
+                               if (dt == null) {\r
+                                       dt = new DataTable (tableName);\r
+                                       Tables.Add (dt);\r
+                               }\r
+                               dt.Load (reader, loadOption);\r
+                               reader.NextResult ();\r
+                       }\r
+               }\r
+\r
+               public virtual void Load (IDataReader reader, LoadOption loadOption,\r
+                                         FillErrorEventHandler errorHandler, params DataTable[] tables)\r
+               {\r
+                       if (reader == null)\r
+                               throw new ArgumentNullException ("Value cannot be null. Parameter name: reader");\r
+\r
+                       foreach (DataTable dt in tables) {\r
+                               if (dt.DataSet == null || dt.DataSet != this)\r
+                                       throw new ArgumentException ("Table " + dt.TableName + " does not belong to this DataSet.");\r
+                               dt.Load (reader, loadOption, errorHandler);\r
+                               reader.NextResult ();\r
+                       }\r
+               }\r
+\r
+               void BinarySerialize (SerializationInfo si)\r
+               {\r
+                       Version vr = new Version(2, 0);\r
+                       si.AddValue ("DataSet.RemotingVersion", vr, typeof (Version));\r
+                       si.AddValue ("DataSet.RemotingFormat", RemotingFormat, typeof (SerializationFormat));\r
+                       si.AddValue ("DataSet.DataSetName", DataSetName);\r
+                       si.AddValue ("DataSet.Namespace", Namespace);\r
+                       si.AddValue ("DataSet.Prefix", Prefix);\r
+                       si.AddValue ("DataSet.CaseSensitive", CaseSensitive);\r
+                       si.AddValue ("DataSet.LocaleLCID", Locale.LCID);\r
+                       si.AddValue ("DataSet.EnforceConstraints", EnforceConstraints);\r
+                       si.AddValue ("DataSet.ExtendedProperties", properties, typeof (PropertyCollection));\r
+\r
+                       Tables.BinarySerialize_Schema (si);\r
+                       Tables.BinarySerialize_Data (si);\r
+\r
+                       Relations.BinarySerialize (si);\r
+               }\r
+\r
+               void BinaryDeserialize (SerializationInfo info)\r
+               {\r
+                       ArrayList arrayList = null;\r
+\r
+                       DataSetName = info.GetString ("DataSet.DataSetName");\r
+                       Namespace = info.GetString ("DataSet.Namespace");\r
+                       CaseSensitive = info.GetBoolean ("DataSet.CaseSensitive");\r
+                       Locale = new CultureInfo (info.GetInt32 ("DataSet.LocaleLCID"));\r
+                       EnforceConstraints = info.GetBoolean ("DataSet.EnforceConstraints");\r
+                       Prefix = info.GetString ("DataSet.Prefix");\r
+                       /*\r
+                         FIXME: Private variable available in SerializationInfo\r
+                         this.RemotingVersion = (System.Version) info.GetValue("DataSet.RemotingVersion",\r
+                         typeof(System.Version));\r
+                       */\r
+                       properties = (PropertyCollection) info.GetValue ("DataSet.ExtendedProperties",\r
+                                                                        typeof (PropertyCollection));\r
+                       int tableCount = info.GetInt32 ("DataSet.Tables.Count");\r
+\r
+                       Byte [] bytes;\r
+                       DataTable dt = null;\r
+                       for (int i = 0; i < tableCount; i++) {\r
+                               bytes = (Byte []) info.GetValue ("DataSet.Tables_" + i,\r
+                                                                typeof (Byte[]));\r
+                               MemoryStream ms = new MemoryStream (bytes);\r
+                               BinaryFormatter bf = new BinaryFormatter ();\r
+                               dt = (DataTable) bf.Deserialize (ms);\r
+                               ms.Close ();\r
+                               for (int j = 0; j < dt.Columns.Count; j++) {\r
+                                       dt.Columns[j].Expression = info.GetString ("DataTable_" + i +\r
+                                                                                  ".DataColumn_" + j +\r
+                                                                                  ".Expression");\r
+                               }\r
+                               /*\r
+                                 Not using\r
+                                 int rowsCount = info.GetInt32 ("DataTable_" + i + ".Rows.Count");\r
+                                 int recordsCount = info.GetInt32 ("DataTable_" + i + ".Records.Count");\r
+                               */\r
+                               ArrayList nullBits = (ArrayList) info.GetValue ("DataTable_" + i + ".NullBits",\r
+                                                                               typeof (ArrayList));\r
+                               arrayList = (ArrayList) info.GetValue ("DataTable_" + i + ".Records",\r
+                                                                      typeof (ArrayList));\r
+                               BitArray rowStateBitArray = (BitArray) info.GetValue ("DataTable_" + i + ".RowStates",\r
+                                                                                     typeof (BitArray));\r
+                               dt.DeserializeRecords (arrayList, nullBits, rowStateBitArray);\r
+                               Tables.Add (dt);\r
+                       }\r
+                       for (int i = 0; i < tableCount; i++) {\r
+                               dt = Tables [i];\r
+                               dt.dataSet = this;\r
+                               arrayList = (ArrayList) info.GetValue ("DataTable_" + i + ".Constraints",\r
+                                                                      typeof (ArrayList));\r
+                               if (dt.Constraints == null)\r
+                                       dt.Constraints = new ConstraintCollection (dt);\r
+                               dt.DeserializeConstraints (arrayList);\r
+                       }\r
+                       arrayList = (ArrayList) info.GetValue ("DataSet.Relations",\r
+                                                              typeof (ArrayList));\r
+                       bool bParentColumn = true;\r
+                       for (int l = 0; l < arrayList.Count; l++) {\r
+                               ArrayList tmpArrayList = (ArrayList) arrayList[l];\r
+                               ArrayList childColumns = new ArrayList ();\r
+                               ArrayList parentColumns = new ArrayList ();\r
+                               for (int k = 0; k < tmpArrayList.Count; k++) {\r
+                                       if (tmpArrayList[k] != null && typeof (int) == tmpArrayList[k].GetType().GetElementType()) {\r
+                                               Array dataColumnArray = (Array)tmpArrayList[k];\r
+                                               if (bParentColumn) {\r
+                                                       parentColumns.Add (Tables [(int) dataColumnArray.GetValue (0)].\r
+                                                                          Columns [(int) dataColumnArray.GetValue (1)]);\r
+                                                       bParentColumn = false;\r
+                                               }\r
+                                               else {\r
+                                                       childColumns.Add (Tables [(int) dataColumnArray.GetValue (0)].\r
+                                                                         Columns [(int) dataColumnArray.GetValue (1)]);\r
+                                                       bParentColumn = true;\r
+                                               }\r
+                                       }\r
+                               }\r
+                               Relations.Add ((string) tmpArrayList [0],\r
+                                              (DataColumn []) parentColumns.ToArray (typeof (DataColumn)),\r
+                                              (DataColumn []) childColumns.ToArray (typeof (DataColumn)),\r
+                                              false);\r
+                       }\r
+               }\r
+\r
+               private void OnDataSetInitialized (EventArgs e)\r
+               {\r
+                       if (null != Initialized)\r
+                               Initialized (this, e);\r
+               }\r
+\r
+               private void DataSetInitialized ()\r
+               {\r
+                       EventArgs e = new EventArgs ();\r
+                       OnDataSetInitialized (e);\r
+               }\r
+\r
+               protected virtual void InitializeDerivedDataSet ()\r
+               {\r
+               }\r
+\r
+               protected SchemaSerializationMode DetermineSchemaSerializationMode (XmlReader reader)\r
+               {\r
+                       return SchemaSerializationMode.IncludeSchema;\r
+               }\r
+\r
+               protected SchemaSerializationMode DetermineSchemaSerializationMode (SerializationInfo info, StreamingContext context)\r
+               {\r
+                       SerializationInfoEnumerator e = info.GetEnumerator ();\r
+                       while (e.MoveNext ()) {\r
+                               if (e.Name == "SchemaSerializationMode.DataSet") {\r
+                                       return (SchemaSerializationMode) e.Value;\r
+                               }\r
+                       }\r
+                       \r
+                       return SchemaSerializationMode.IncludeSchema;\r
+               }\r
+\r
+               protected bool IsBinarySerialized (SerializationInfo info, StreamingContext context)\r
+               {\r
+                       SerializationInfoEnumerator e = info.GetEnumerator ();\r
+                       while (e.MoveNext ()) {\r
+                               if (e.ObjectType == typeof (System.Data.SerializationFormat))\r
+                                       return true;\r
+                       }\r
+                       return false;\r
+               }\r
+       }\r
+#endif\r
 }\r