You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public class FooNullableDateTime
{
[System.Xml.Serialization.XmlElementAttribute("DateValue", DataType = "date")]
public Nullable<DateTime> DateValue { get; set; }
}
[Test]
public void SerializeNullableDateTime()
{
var value = new FooNullableDateTime
{
DateValue = new DateTime(2011, 11, 10),
};
var serializer = GetSerializer();
var actual = serializer.ToXml(value);
var expected =
@"<fooNullableDateTime xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""><DateValue>2011-11-10</DateValue></fooNullableDateTime>";
Assert.That(actual, IsXml.Equals(expected).WithIgnoreDeclaration());
}
Result:
XML documents are Different.
TextValue:
Expected: 2011-11-10 at "/fooNullableDateTime/DateValue/text()" (1:87)
Actual: 2011-11-10T00:00:00 at "/fooNullableDateTime/DateValue/text()" (1:126)
Serializer ignores DataType="date" value and serialize value as dateTime.
XmlNullableConverter contains this informaion in context:
But SerializeBody creates a new context with an empty XmlMember:
The text was updated successfully, but these errors were encountered:
Result:
Serializer ignores
DataType="date"
value and serialize value as dateTime.XmlNullableConverter
contains this informaion in context:But

SerializeBody
creates a new context with an emptyXmlMember
:The text was updated successfully, but these errors were encountered: