I have following code:
public sealed class MyClass
{
[XmlElement("Remind")]
public string lastUpdatedTimeForXml2
{
get { return Remind.ToString("yyyy-MM-ddTHH:mm:ss"); }
set { Remind = DateTimeOffset.Parse(value); }
}
[XmlIgnore]
public DateTimeOffset Remind { get; set; }
}
And my problem is when the Remind value not exist in file it's replacing it by 0001-01-01T00:00:00 and crashing at line: "set { Remind = DateTimeOffset.Parse(value); }"
EDIT.
Ok, I solved it doing something like this:
[XmlElement("Remind")]
public string lastUpdatedTimeForXml2
{
get { return Remind.ToString("yyyy-MM-ddTHH:mm:ss"); }
set
{
if (value == "0001-01-01T00:00:00")
Remind = DateTimeOffset.MinValue;
else
Remind = DateTimeOffset.Parse(value);
}
}
[XmlIgnore]
Now isn't crashing, but i don't know why. This is the best solution?