2006-11-20 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Mon, 20 Nov 2006 07:44:28 +0000 (07:44 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Mon, 20 Nov 2006 07:44:28 +0000 (07:44 -0000)
* TypeTranslator.cs : (GetTypeData) when the argument type is
  Nullable<T>, use T instead. At run time (on both interpreter and
  generated code) it is converted to T. Fixed bug #79803.

* XmlSerializerTests.cs : added test for nullable type.

svn path=/trunk/mcs/; revision=68175

mcs/class/System.XML/System.Xml.Serialization/ChangeLog
mcs/class/System.XML/System.Xml.Serialization/TypeTranslator.cs
mcs/class/System.XML/Test/System.Xml.Serialization/ChangeLog
mcs/class/System.XML/Test/System.Xml.Serialization/XmlSerializerTests.cs

index 01645d14621b5c2c7fd9009386ef6d72f4d3d6b1..836d682bfd3d3939fddaa9e7e528fbe2c1c22b59 100644 (file)
@@ -1,3 +1,9 @@
+2006-11-20  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * TypeTranslator.cs : (GetTypeData) when the argument type is
+         Nullable<T>, use T instead. At run time (on both interpreter and
+         generated code) it is converted to T. Fixed bug #79803.
+
 2006-11-17  Atsushi Enomoto  <atsushi@ximian.com>
 
        * SerializationCodeGenerator.cs, TypeData.cs :
index 9bad3e92c721facd0d5259ec5800c5c0ec0c0293..96bfde95c98af6b3f0d47c912ef2c0c98bc16077 100644 (file)
@@ -140,8 +140,17 @@ namespace System.Xml.Serialization
                        return GetTypeData (type, null);
                }
 
+               static Type nullable = typeof (int?).GetGenericTypeDefinition ();
+
                public static TypeData GetTypeData (Type type, string xmlDataType)
                {
+#if NET_2_0
+                       // Nullable<T> is serialized as T
+                       if (type.IsGenericType && type.GetGenericTypeDefinition () == nullable) {
+                               type = type.GetGenericArguments () [0];
+                       }
+#endif
+
                        if ((xmlDataType != null) && (xmlDataType.Length != 0)) {
                                // If the type is an array, xmlDataType specifies the type for the array elements,
                                // not for the whole array. The exception is base64Binary, since it is a byte[],
index 065d3b54f01fbf6ee22552bce6238f42fcaae241..178927045e470a6c435ac08ce73722face56ac61 100644 (file)
@@ -1,3 +1,7 @@
+2006-11-20  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * XmlSerializerTests.cs : added test for nullable type.
+
 2006-11-17  Atsushi Enomoto  <atsushi@ximian.com>
 
        * XmlSerializerTests.cs : test for basic generic type support with
index d77ec8194ef8a7e9c8506fc01b1fb9ec116d97d8..b6f72a5c5dc48343b60e5c38eb82a88f7bdbd3d3 100644 (file)
@@ -2133,6 +2133,20 @@ namespace MonoTests.System.XmlSerialization
                                new Type [] {type},
                                new XmlTypeMapping [] {imp.ImportTypeMapping (type)});
                }
+
+               [Test]
+               public void Nullable ()
+               {
+                       XmlSerializer ser = new XmlSerializer (typeof (int?));
+                       int? nullableType = 5;
+                       sw = new StringWriter ();
+                       xtw = new XmlTextWriter (sw);
+                       ser.Serialize (xtw, nullableType);
+                       xtw.Close ();
+                       Assert.AreEqual ("<?xml version=\"1.0\" encoding=\"utf-16\"?><int>5</int>", sw.ToString ());
+                       int? i = (int?) ser.Deserialize (new StringReader (sw.ToString ()));
+                       Assert.AreEqual (5, i);
+               }
 #endif
 
                public class CDataTextNodesType