Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/TimeSpan2XmlSerializer.cs @ 1853

Last change on this file since 1853 was 1853, checked in by epitzer, 15 years ago

Fix EmptyStorableClass attributes. (#603)

File size: 815 bytes
Line 
1using System;
2using HeuristicLab.Persistence.Core;
3using HeuristicLab.Persistence.Interfaces;
4using System.Text;
5using System.Text.RegularExpressions;
6using System.Globalization;
7
8
9namespace HeuristicLab.Persistence.Default.Xml.Primitive {
10
11  public class TimeSpan2XmlSerializer : PrimitiveXmlSerializerBase<TimeSpan> {
12
13    public override XmlString Format(TimeSpan o) {
14      return new XmlString(o.ToString());
15    }
16
17    public override TimeSpan Parse(XmlString t) {
18      try {
19        return TimeSpan.Parse(t.Data);
20      } catch (FormatException x) {
21        throw new PersistenceException("Cannot parse TimeSpan string representation.", x);
22      } catch (OverflowException x) {
23        throw new PersistenceException("Overflow during TimeSpan parsing.", x);
24      }
25    }
26  }
27}
Note: See TracBrowser for help on using the repository browser.