I have a generated object from running the xsd.exe which has the following property with backing field:
private System.DateTime deliveryDateField;
/// <remarks/>
public System.DateTime DeliveryDate
{
get
{
return this.deliveryDateField;
}
set
{
this.deliveryDateField = value;
}
}
this is generated from:
<xs:element name="DeliveryDate" type="xs:dateTime" minOccurs="0"/>
which I am trying to serialize using:
var t = new Transaction();
t.DeliveryDate = new DateTime(2011,11,11);
var xs = new XmlSerializer(t.GetType());
string outString;
using (var ms = new MemoryStream())
{
xs.Serialize(ms, t);
ms.Position = 0;
using (var sr = new StreamReader(ms))
{
outString = sr.ReadToEnd();
}
}
return outString;
whatever value I set this to it is getting lost on the serialization process while other elements are fine. What do I need to do to get this serializing properly?
Thanks
You probably also have a property called DeliveryDateSpecified on your Transaction class? This is because your DeliveryDate is not mandatory. If you set this to true your DeliveryDate will also get serialized.