Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive_Milestone2/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/TimeSpan2XmlSerializer.cs @ 1835

Last change on this file since 1835 was 1823, checked in by epitzer, 16 years ago

Namespace refactoring: rename formatters & decomposers -> primitive and composite serializers. (#603)

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