I would like serialize object to XML. This part is easy. But i would serialize properties (like DateTime) with a specific format.
My current code is this one :
[XmlIgnore]
private DateTime _paymentDate { get; set; }
public string PaymentDate
{
get
{
return this._paymentDate.ToString("yyyy-MM-dd HH:mm:ss");
}
set
{
this._paymentDate = DateTime.ParseExact(value, "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
}
}
But it's very bad. If i have 100 DateTime properties, i should duplicate this code 100 times.
So, i would like to use a formatter (like with Newtonsoft JSON). How can i do it ?
Thanks a lot :)