Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/16/09 12:40:41 (15 years ago)
Author:
epitzer
Message:

Stronger typing for formatters with the help of generics. Separate format and serial data type. (#548)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/DecimalNumber2XmlFormatterBase.cs

    r1554 r1564  
    77namespace HeuristicLab.Persistence.Default.Xml.Primitive { 
    88 
    9   public abstract class DecimalNumber2XmlFormatterBase<T> : IFormatter {
    10 
    11     public Type Type { get { return typeof(T); } }
    12 
    13     public IFormat Format { get { return XmlFormat.Instance; } }
    14 
     9  public abstract class DecimalNumber2XmlFormatterBase<T> : FormatterBase<T, XmlString> {
     10   
    1511    private static MethodInfo ToStringMethod = typeof(T)
    1612      .GetMethod(
     
    3127        null);
    3228
    33     public object DoFormat(object o) {
    34       return ToStringMethod.Invoke(o, new object[] { "r", CultureInfo.InvariantCulture });
     29    public override XmlString Format(T t) {
     30      return new XmlString((string)ToStringMethod.Invoke(t, new object[] { "r", CultureInfo.InvariantCulture }));
    3531    }
    36     public object Parse(object o) {     
    37       return ParseMethod.Invoke(null, new[] { o, CultureInfo.InvariantCulture });
     32    public override T Parse(XmlString x) {     
     33      return (T)ParseMethod.Invoke(null, new object[] { x.Data, CultureInfo.InvariantCulture });
    3834    }
    3935  } 
Note: See TracChangeset for help on using the changeset viewer.