+2007-10-26 Atsushi Enomoto <atsushi@ximian.com>
+
+ * TypeTranslator.cs, XmlCustomFormatter.cs : looks like duration is
+ serialized to System.String, not TimeSpan. Fixed bug #336625.
+
2007-09-27 Atsushi Enomoto <atsushi@ximian.com>
* XmlMapping.cs : added XsdElementName.
nameCache.Add (typeof (byte[]), new TypeData (typeof (byte[]), "base64Binary", true));
nameCache.Add (typeof (XmlNode), new TypeData (typeof (XmlNode), "XmlNode", false));
nameCache.Add (typeof (XmlElement), new TypeData (typeof (XmlElement), "XmlElement", false));
- nameCache.Add (typeof (TimeSpan), new TypeData (typeof (TimeSpan), "duration", true));
+ // The key type is wrong (must be string), but otherwise it cannot be added to Hashtable!
+ nameCache.Add (typeof (TimeSpan), new TypeData (typeof (string), "duration", true));
primitiveTypes = new Hashtable();
ICollection types = nameCache.Values;
case "base64":
case "base64Binary": return value == null ? String.Empty : Convert.ToBase64String ((byte[])value);
case "hexBinary": return value == null ? String.Empty : XmlConvert.ToBinHexString ((byte[]) value);
- case "duration": return XmlConvert.ToString ((TimeSpan) value);
+ case "duration": return (string) value;
default: return value is IFormattable ? ((IFormattable) value).ToString (null, CultureInfo.InvariantCulture) : value.ToString ();
}
}
case "base64":
case "base64Binary": return Convert.FromBase64String (value);
case "hexBinary": return XmlConvert.FromBinHexString (value);
- case "duration": return XmlConvert.ToTimeSpan (value);
+ case "duration": return value;
default:
if (type.Type != null)
return Convert.ChangeType (value, type.Type);
case "base64":
case "base64Binary": return value + " == null ? String.Empty : Convert.ToBase64String (" + value + ")";
case "hexBinary": return value + " == null ? String.Empty : ToBinHexString (" + value + ")";
- case "duration": return "XmlConvert.ToString (" + value + ")";
+ case "duration": return value;
case "NMTOKEN":
case "Name":
case "NCName":
case "base64:":
case "base64Binary": return "Convert.FromBase64String (" + value + ")";
case "hexBinary": return "FromBinHexString (" + value + ")";
- case "duration": return "XmlConvert.ToTimeSpan (" + value + ")";
+ case "duration": return value;
default: return value;
}
}
+2007-10-26 Atsushi Enomoto <atsushi@ximian.com>
+
+ * XmlSerializerTests.cs : added test for DataType in [XmlElement].
+
2007-09-25 Atsushi Enomoto <atsushi@ximian.com>
* XmlSerializerTests.cs : another XmlSchemaProvider test; use it
Assert.AreEqual (Infoset (expected), WriterText);
}
+ [Test]
+ public void SerializeDurationToString ()
+ {
+ XmlSerializer ser = new XmlSerializer (typeof (TimeSpanContainer1));
+ ser.Serialize (TextWriter.Null, new TimeSpanContainer1 ());
+ }
+
+ [Test]
+ [ExpectedException (typeof (InvalidOperationException))]
+ public void SerializeDurationToTimeSpan ()
+ {
+ XmlSerializer ser = new XmlSerializer (typeof (TimeSpanContainer2));
+ ser.Serialize (TextWriter.Null, new TimeSpanContainer2 ());
+ }
+
+ [Test]
+ [ExpectedException (typeof (InvalidOperationException))]
+ public void SerializeInvalidDataType ()
+ {
+ XmlSerializer ser = new XmlSerializer (typeof (InvalidTypeContainer));
+ ser.Serialize (TextWriter.Null, new InvalidTypeContainer ());
+ }
+
#region GenericsSeralizationTests
#if NET_2_0
public string Value;
}
+ public class InvalidTypeContainer
+ {
+ [XmlElement (DataType = "invalid")]
+ public string InvalidTypeItem = "aaa";
+ }
+
+ public class TimeSpanContainer1
+ {
+ [XmlElement (DataType = "duration")]
+ public string StringDuration = "aaa";
+ }
+
+ public class TimeSpanContainer2
+ {
+ [XmlElement (DataType = "duration")]
+ public TimeSpan StringDuration = TimeSpan.FromSeconds (1);
+ }
+
#if NET_2_0
public class Bug80759
{