Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/DateTime2XmlFormatter.cs @ 1625

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

Added PersistenceException used consistently for all error conditions in the persistence framework (#548)

File size: 723 bytes
Line 
1using System;
2using HeuristicLab.Persistence.Core;
3using HeuristicLab.Persistence.Interfaces;
4using HeuristicLab.Persistence.Default.Decomposers.Storable;
5
6namespace HeuristicLab.Persistence.Default.Xml.Primitive {
7
8  [EmptyStorableClass]
9  public class DateTime2XmlFormatter : FormatterBase<DateTime, XmlString> {
10
11    public override XmlString Format(DateTime dt) {
12      return new XmlString(dt.Ticks.ToString());
13    }
14
15    public override DateTime Parse(XmlString x) {
16      try {
17        return new DateTime(long.Parse(x.Data));
18      } catch (Exception e) {
19        throw new PersistenceException("Exception caugth while trying to reconstruct DateTime object.", e);
20      }
21    }
22
23  }
24
25
26}
Note: See TracBrowser for help on using the repository browser.