Free cookie consent management tool by TermsFeed Policy Generator

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

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

Fix EmptyStorableClass attributes. (#603)

File size: 912 bytes
Line 
1using System;
2using HeuristicLab.Persistence.Core;
3using HeuristicLab.Persistence.Interfaces;
4using System.Reflection;
5using System.Globalization;
6
7namespace HeuristicLab.Persistence.Default.Xml.Primitive {
8
9  public abstract class SimpleNumber2XmlSerializerBase<T> : PrimitiveXmlSerializerBase<T> {
10
11    private static MethodInfo ParseMethod = typeof(T)
12      .GetMethod(
13        "Parse",
14        BindingFlags.Static | BindingFlags.Public,
15        null,
16        CallingConventions.Standard,
17        new[] { typeof(string) },
18        null);
19
20    public override XmlString Format(T t) {
21      return new XmlString(t.ToString());
22    }
23
24    public override T Parse(XmlString x) {
25      try {
26        return (T)ParseMethod.Invoke(null, new[] { x.Data });
27      } catch (Exception e) {
28        throw new PersistenceException("Could not parse simple number.", e);
29      }
30    }
31  }
32}
Note: See TracBrowser for help on using the repository browser.