+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 :
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[],
+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
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