Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/DecimalNumber2XmlSerializerBase.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: 1.3 KB
RevLine 
[1554]1using System;
2using HeuristicLab.Persistence.Core;
3using HeuristicLab.Persistence.Interfaces;
4using System.Reflection;
5using System.Globalization;
6
[1566]7namespace HeuristicLab.Persistence.Default.Xml.Primitive {
8
[1823]9  public abstract class DecimalNumber2XmlSerializerBase<T> : PrimitiveXmlSerializerBase<T> {
[1566]10
[1554]11    private static MethodInfo ToStringMethod = typeof(T)
12      .GetMethod(
13        "ToString",
14        BindingFlags.Instance | BindingFlags.Public,
15        null,
16        CallingConventions.Standard,
17        new[] { typeof(string), typeof(IFormatProvider) },
18        null);
19
20    private static MethodInfo ParseMethod = typeof(T)
21      .GetMethod(
22        "Parse",
23        BindingFlags.Static | BindingFlags.Public,
24        null,
25        CallingConventions.Standard,
26        new[] { typeof(string), typeof(IFormatProvider) },
27        null);
28
[1564]29    public override XmlString Format(T t) {
30      return new XmlString((string)ToStringMethod.Invoke(t, new object[] { "r", CultureInfo.InvariantCulture }));
[1554]31    }
[1566]32    public override T Parse(XmlString x) {
[1625]33      try {
34        return (T)ParseMethod.Invoke(null, new object[] { x.Data, CultureInfo.InvariantCulture });
35      } catch (Exception e) {
36        throw new PersistenceException("Could not parse decimal number.", e);
37      }
[1554]38    }
[1566]39  }
[1554]40}
Note: See TracBrowser for help on using the repository browser.