To serialize XML, you need to implement IXmlSerializable, not ISerializable.
However, you can get around this with the helper property and mark the properties with an DateTimeattribute XmlIgnore.
public class Foo
{
[XmlIgnore]
public DateTime Bar { get; set; }
public string BarFormatted
{
get { return this.Bar.ToString("dd-MM-yyyy"); }
set { this.Bar = DateTime.ParseExact(value, "dd-MM-yyyy", null); }
}
}
source
share