if (type.IsGenericType && type.GetGenericTypeDefinition () == typeof (Nullable<>)) {
nullableOverride = true;
type = type.GetGenericArguments () [0];
-
- TypeData pt = GetTypeData (type); // beware this recursive call btw ...
- if (pt != null) {
- TypeData tt = (TypeData) nullableTypes [pt.XmlType];
-#if TARGET_JVM
- if (tt == null)
- tt = (TypeData) AppDomain_nullableTypes [pt.XmlType];
-#endif
- if (tt == null) {
- tt = new TypeData (type, pt.XmlType, false);
- tt.IsNullable = true;
-#if TARGET_JVM
- AppDomain_nullableTypes [pt.XmlType] = tt;
-#else
- nullableTypes [pt.XmlType] = tt;
-#endif
- }
- return tt;
- }
}
-#endif
+
if ((xmlDataType != null) && (xmlDataType.Length != 0)) {
// If the type is an array, xmlDataType specifies the type for the array elements,
else
throw new InvalidOperationException ("Cannot convert values of type '" + type.GetElementType () + "' to '" + xmlDataType + "'");
}
+ if (nullableOverride){
+ TypeData tt = (TypeData) nullableTypes [at.XmlType];
+ if (tt == null){
+ tt = new TypeData (type, at.XmlType, false);
+ tt.IsNullable = true;
+ nullableTypes [at.XmlType] = tt;
+ }
+ return tt;
+ }
return at;
}
+ if (nullableOverride){
+ TypeData pt = GetTypeData (type); // beware this recursive call btw ...
+ if (pt != null) {
+ TypeData tt = (TypeData) nullableTypes [pt.XmlType];
+#if TARGET_JVM
+ if (tt == null)
+ tt = (TypeData) AppDomain_nullableTypes [pt.XmlType];
+#endif
+ if (tt == null) {
+ tt = new TypeData (type, pt.XmlType, false);
+ tt.IsNullable = true;
+#if TARGET_JVM
+ AppDomain_nullableTypes [pt.XmlType] = tt;
+#else
+ nullableTypes [pt.XmlType] = tt;
+#endif
+ }
+ return tt;
+ }
+ }
+#endif
+
TypeData typeData = nameCache[runtimeType] as TypeData;
if (typeData != null) return typeData;
// Author: Erik LeBel <eriklebel@yahoo.ca>
//
// (C) Erik LeBel 2003
+// Copyright 2003-2011 Novell
+// Copyright 2011 Xamarin Inc
//
// FIXME add tests for callbacks
// FIXME add tests for writes that generate namespaces
[DefaultValue ('a')]
public char character = '\'';
}
+
+ [Test]
+ public void TestNullableDatesAndTimes ()
+ {
+ DateTime dt = new DateTime (2012, 1, 3, 10, 0, 0, 0);
+
+ var d = new NullableDatesAndTimes () {
+ MyTime = dt,
+ MyTimeNullable = dt,
+ MyDate = dt,
+ MyDateNullable = dt
+ };
+
+ XmlSerializer ser = new XmlSerializer (d.GetType ());
+ StringWriter sw = new StringWriter ();
+ ser.Serialize (sw, d);
+ string str = sw.ToString ();
+
+ Assert.IsTrue (str.IndexOf ("<MyTime>10:00:00</MyTime>") != -1, "Time");
+ Assert.IsTrue (str.IndexOf ("<MyTimeNullable>10:00:00</MyTimeNullable>") != -1, "Nullable Time");
+ Assert.IsTrue (str.IndexOf ("<MyDate>2012-01-03</MyDate>") != -1, "Date");
+ Assert.IsTrue (str.IndexOf ("<MyDateNullable>2012-01-03</MyDateNullable>") != -1, "Nullable Datwe");
+ }
+
+
}
}
[XmlAttribute]
public string Child3;
}
+
+ [XmlRoot ("root")]
+ public class NullableDatesAndTimes {
+ [XmlElementAttribute ("MyTime", DataType = "time", IsNullable = false)]
+ public DateTime MyTime;
+
+ [XmlElementAttribute ("MyTimeNullable", DataType = "time", IsNullable = true)]
+ public DateTime? MyTimeNullable;
+
+ [XmlElementAttribute ("MyDate", DataType = "date", IsNullable = false)]
+ public DateTime MyDate;
+
+ [XmlElementAttribute ("MyDateNullable", DataType = "date", IsNullable = true)]
+ public DateTime? MyDateNullable;
+ }
}