Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/SimpleNumber2XmlFormatterBase.cs @ 1554

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

XML formatters for all primitive numeric types. (#548)

File size: 859 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 SimpleNumber2XmlFormatterBase<T> : IFormatter {
10
11    public Type Type { get { return typeof(T); } }
12
13    public IFormat Format { get { return XmlFormat.Instance; } }
14
15    private static MethodInfo ParseMethod = typeof(T)
16      .GetMethod(
17        "Parse",
18        BindingFlags.Static | BindingFlags.Public,
19        null,
20        CallingConventions.Standard,
21        new[] { typeof(string) },
22        null);
23
24    public object DoFormat(object o) {
25      return ((T)o).ToString();
26    }
27    public object Parse(object o) {
28      return ParseMethod.Invoke(null, new[] { o });     
29    }
30  } 
31}
Note: See TracBrowser for help on using the repository browser.