jump to navigation

Archive: Evil Bug – Serialization of TimeSpan object. May 3, 2008

Posted by reddogaw in .NET General, Archive.
Tags: , ,
trackback

From: http://blogs.ssw.com.au/andrewweaver/archive/2004/05/22/201.aspx

I’m using XML Serialization to get the XML for one my classes for public storage. This class has a public property of type TimeSpan… My evil bug is that despite the doco saying that the timespan would get serialized, it didn’t!

Resolved it by making the main property be ignored by serializer, and then a new property based on the Ticks for the TimeSpan:

[XmlIgnore]
public TimeSpan DailyInterval
{
    get { return m_Interval; }
    set { m_Interval = value; }
}

public long DailyIntervalTicks
{
    get { return m_Interval.Ticks; }
    set { m_Interval = new TimeSpan(value); }
}

Some other dude had the same problem (along with many others) and attempted to explain it…

Comments»

No comments yet — be the first.