[Mono-bugs] [Bug 67627][Wis] New - DataSet.Clone needs to return a DataSet with the same subclass

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Tue, 5 Oct 2004 15:50:07 -0400 (EDT)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by rscaletta@augustmack.com.

http://bugzilla.ximian.com/show_bug.cgi?id=67627

--- shadow/67627	2004-10-05 15:50:07.000000000 -0400
+++ shadow/67627.tmp.24458	2004-10-05 15:50:07.000000000 -0400
@@ -0,0 +1,71 @@
+Bug#: 67627
+Product: Mono: Class Libraries
+Version: unspecified
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: Sys.Data
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: rscaletta@augustmack.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: DataSet.Clone needs to return a DataSet with the same subclass
+
+Description of Problem:
+According to MSDN documentation for DataSet.Clone(), 
+"Note   If these classes have been subclassed, the clone will also be of
+the same subclasses."
+
+Instead, on Mono 1.0 Clone returns a generic DataSet.
+
+Steps to reproduce the problem:
+1. Inherit from DataSet
+2. Call derived dataset.clone()
+
+Actual Results:
+A dataset of the same derived type.
+
+Expected Results:
+A plain old DataSet.
+
+How often does this happen? 
+Every time.
+
+Additional Information:
+Hacked around in DataSet.cs... 
+here's the new function, note that the noarg constructor for "typed
+datasets" created by xsd.exe always creates tables.  We make sure that they
+are not added twice.
+
+----------
+
+public virtual DataSet Clone ()
+{
+    // need to return the same type as this...
+    DataSet Copy = (DataSet) Activator.CreateInstance(GetType(), true);
+	
+    CopyProperties (Copy);
+
+
+    foreach (DataTable Table in Tables) {
+        // tables are often added in no-args constructor, don't add them
+        // twice.
+        if (!Copy.Tables.Contains(Table.TableName)) {
+	    Copy.Tables.Add (Table.Clone ());
+        }
+    }
+
+    //Copy Relationships between tables after existance of tables
+    //and setting properties correctly
+    CopyRelations (Copy);
+			
+    return Copy;
+}
+
+------------------------
+Also, DataTable.Clone() doesn't work either.  I will add another bug for that.