[Mono-bugs] [Bug 79278][Min] Changed - XmlSerializer requires default public constructor on Mono, but not on MS.NET
bugzilla-daemon at bugzilla.ximian.com
bugzilla-daemon at bugzilla.ximian.com
Mon Sep 4 18:29:15 EDT 2006
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 robertj at gmx.net.
http://bugzilla.ximian.com/show_bug.cgi?id=79278
--- shadow/79278 2006-09-04 13:55:01.000000000 -0400
+++ shadow/79278.tmp.2689 2006-09-04 18:29:15.000000000 -0400
@@ -71,6 +71,49 @@
From ECMA 335 Page 40
"a public constructor taking no arguments (the default constructor),"
From ECMA 334 Page 128
"All value types implicitly declare a public parameterless instance
constructor called the default constructor."
+
+------- Additional Comments From robertj at gmx.net 2006-09-04 18:29 -------
+
+Since even the deserialization works, this is probably not
+an oversight/bug. It's rather a mistake in the documentation.
+
+Test case for both sides (it should print True\nTrue)
+
+// C# 2.0
+using System;
+using System.IO;
+using System.Text;
+using System.Xml.Serialization;
+
+public class Test {
+
+ public string Message = "hello";
+
+ private Test ()
+ {
+ }
+
+ static void Main()
+ {
+ Test a = new Test ();
+ Test b = Clone<Test> (a);
+ Console.WriteLine (a.Message == b.Message);
+ Console.WriteLine (!a.Equals (b));
+ }
+
+ public static T Clone<T> (T data)
+ {
+ StringBuilder b = new StringBuilder ();
+ XmlSerializer x = new XmlSerializer (data.GetType ());
+ TextWriter w = new StringWriter (b);
+ x.Serialize (w, data);
+ w.Close ();
+ x = new XmlSerializer (data.GetType ());
+ TextReader r = new StringReader (b.ToString());
+ return (T) x.Deserialize (r);
+ }
+}
+
More information about the mono-bugs
mailing list