One way to handle this is to decorate the DateTime member with
[System.Xml.Serialization.XmlIgnore]
This tells the serializer to not serialize or de-serialize it at all.
Then, add an additional property to the class, called, for example DateString. It might be defined as
public string DateString {
set { ... }
get { ... }
}
Then you can serialize and de-ser the DateString in the get/set logic:
public string DateString {
set {
// parse value here - de-ser from your chosen format
// use constructor, eg, Timestamp= new System.DateTime(....);
// or use one of the static Parse() overloads of System.DateTime()
}
get {
return Timestamp.ToString("yyyy.MM.dd"); // serialize to whatever format you want.
}
}
Within the get and set you are manipulating the value of the Date member, but you are doing it with custom logic. The serialized property need not be a string of course, but that is a simple way to do it. You could also ser/de-ser using an int, as with the unix epoch, for example
by Dino Chiesa