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 | |
---|
1 | using System;
|
---|
2 | using HeuristicLab.Persistence.Core;
|
---|
3 | using HeuristicLab.Persistence.Interfaces;
|
---|
4 | using System.Reflection;
|
---|
5 | using System.Globalization;
|
---|
6 |
|
---|
7 | namespace 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.