Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1554


Ignore:
Timestamp:
04/14/09 14:15:22 (16 years ago)
Author:
epitzer
Message:

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

Location:
trunk/sources
Files:
12 added
1 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Persistence.Test/NewSerializationTest.cs

    r1553 r1554  
    237237      XmlGenerator.Serialize(sdt, "test5.zip");
    238238      object o = XmlParser.DeSerialize("test5.zip");
    239       Console.WriteLine(ViewOnlyGenerator.Serialize(sdt));
    240       Console.WriteLine(ViewOnlyGenerator.Serialize(o));
     239      //Console.WriteLine(ViewOnlyGenerator.Serialize(sdt));
     240      //Console.WriteLine(ViewOnlyGenerator.Serialize(o));
    241241    }
    242242
     
    273273      Console.WriteLine(ViewOnlyGenerator.Serialize(o));
    274274    }
     275   
     276    class Float {
     277      [Storable]
     278      float f = 12.3f;
     279    }
     280
     281    public static void Test9() {           
     282      XmlGenerator.Serialize(12.3f, "test9.zip");
     283      object o = XmlParser.DeSerialize("test9.zip");
     284      Console.WriteLine(ViewOnlyGenerator.Serialize(12.3f));
     285      Console.WriteLine(ViewOnlyGenerator.Serialize(o));
     286    }
    275287
    276288
    277289    public static void Main() {
    278290      BasicConfigurator.Configure();
     291      ConfigurationService.Instance.Reset();
    279292      Test1();     
    280293      Test2();
    281294      Test3();
    282295      Test4();
    283       //Test5();
     296      Test5();
    284297      Test6();
    285298      Test7();
    286299      Test8();
     300      Test9();
    287301      //SpeedTest();
    288302      //SpeedTest2();
  • trunk/sources/HeuristicLab.Persistence/3.3/Core/ConfigurationService.cs

    r1542 r1554  
    107107            }
    108108            Formatters[formatter.Format].Add(formatter);
     109            Logger.Debug("discovered formatter " + t.VersionInvariantName());
    109110          } catch (MissingMethodException e) {
    110111            Logger.Warn("Could not instantiate " + t.VersionInvariantName(), e);           
    111           }         
     112          } catch (ArgumentException e) {
     113            Logger.Warn("Could not instantiate " + t.VersionInvariantName(), e);
     114          }
    112115        }
    113116        if (t.GetInterface(typeof (IDecomposer).FullName) != null) {
    114117          try {
    115118            Decomposers.Add((IDecomposer) Activator.CreateInstance(t, true));
     119            Logger.Debug("discovered decomposer " + t.VersionInvariantName());
    116120          } catch (MissingMethodException e) {
    117             Logger.Warn("Could not instantiate " + t.VersionInvariantName(), e);           
     121            Logger.Warn("Could not instantiate " + t.VersionInvariantName(), e);         
     122          } catch (ArgumentException e) {
     123            Logger.Warn("Could not instantiate " + t.VersionInvariantName(), e);
    118124          }
    119125        }
  • trunk/sources/HeuristicLab.Persistence/3.3/Default/ViewOnly/ViewOnlyFormat.cs

    r1553 r1554  
    4545  public class Type2ViewFormatter : ValueType2ViewFormatter {
    4646    public override Type Type { get { return typeof(Type); } }
     47  }
     48
     49  public class Float2ViewFormatter : ValueType2ViewFormatter {
     50    public override Type Type { get { return typeof(float); } }
    4751  }
    4852
  • trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/Double2XmlFormatter.cs

    r1454 r1554  
    11using System;
    2 using System.Globalization;
    32using HeuristicLab.Persistence.Core;
    43using HeuristicLab.Persistence.Interfaces;
     4using System.Reflection;
     5using System.Globalization;
    56
    6 namespace HeuristicLab.Persistence.Default.Xml.Primitive {
    7 
     7namespace HeuristicLab.Persistence.Default.Xml.Primitive { 
     8   
    89  [EmptyStorableClass]
    9   public class Double2XmlFormatter : IFormatter {   
    10 
    11     public Type Type { get { return typeof(double); } }
    12     public IFormat Format { get { return XmlFormat.Instance; } }
    13 
    14     public object DoFormat(object o) {
    15       return ((double)o).ToString("r", CultureInfo.InvariantCulture);     
    16     }
    17 
    18     public object Parse(object o) {
    19       return double.Parse((string)o, CultureInfo.InvariantCulture);
    20     }
    21 
    22   }
     10  public class Double2XmlFormatter : DecimalNumber2XmlFormatterBase<double> { }
    2311 
    2412}
  • trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/Int2XmlFormatter.cs

    r1454 r1554  
    22using HeuristicLab.Persistence.Core;
    33using HeuristicLab.Persistence.Interfaces;
     4using System.Reflection;
     5using System.Globalization;
    46
    5 namespace HeuristicLab.Persistence.Default.Xml.Primitive {
     7namespace HeuristicLab.Persistence.Default.Xml.Primitive { 
    68
    79  [EmptyStorableClass]
    8   public class Int2XmlFormatter : IFormatter {
    9 
    10     public Type Type { get { return typeof(int); } }
    11     public IFormat Format { get { return XmlFormat.Instance; } }
    12 
    13     public object DoFormat(object o) {
    14       return ((int)o).ToString();
    15     }
    16 
    17     public object Parse(object o) {
    18       return int.Parse((string)o);
    19     }
    20 
    21   }
     10  public class Int2XmlFormatter : SimpleNumber2XmlFormatterBase<int> { }
    2211 
    2312}
  • trunk/sources/HeuristicLab.Persistence/3.3/HeuristicLab.Persistence-3.3.csproj

    r1553 r1554  
    112112    <Compile Include="Core\DataMemberAccessor.cs" />
    113113    <Compile Include="Default\Xml\Compact\IntList2XmlFormatter.cs" />
     114    <Compile Include="Default\Xml\Primitive\Double2XmlFormatterBase.cs" />
     115    <Compile Include="Default\Xml\Primitive\Decimal2XmlFormatterBase.cs" />
     116    <Compile Include="Default\Xml\Primitive\Float2XmlFormatterBase.cs" />
     117    <Compile Include="Default\Xml\Primitive\UInt2XmlFormatter.cs" />
     118    <Compile Include="Default\Xml\Primitive\Long2XmlFormatter.cs" />
     119    <Compile Include="Default\Xml\Primitive\ULong2XmlFormatter.cs" />
     120    <Compile Include="Default\Xml\Primitive\Int2XmlFormatter.cs" />
     121    <Compile Include="Default\Xml\Primitive\SByte2XmlFormatter.cs" />
     122    <Compile Include="Default\Xml\Primitive\Byte2XmlFormatter.cs" />
     123    <Compile Include="Default\Xml\Primitive\Short2XmlFormatter.cs" />
     124    <Compile Include="Default\Xml\Primitive\UShort2XmlFormatter.cs" />
     125    <Compile Include="Default\Xml\Primitive\Bool2XmlFormatter.cs" />
     126    <Compile Include="Default\Xml\Primitive\DecimalNumber2XmlFormatterBase.cs" />
    114127    <Compile Include="Default\Xml\Primitive\String2XmlFormatter.cs" />
    115     <Compile Include="Default\Xml\Primitive\Int2XmlFormatter.cs" />
    116     <Compile Include="Default\Xml\Primitive\Double2XmlFormatter.cs" />
    117     <Compile Include="Default\Xml\Primitive\Boolean2XmlFormatter.cs" />
     128    <Compile Include="Default\Xml\Primitive\SimpleNumber2XmlFormatterBase.cs" />
    118129    <Compile Include="Default\Xml\Primitive\DateTime2XmlFormatter.cs" />
    119130    <Compile Include="Default\Xml\XmlFormat.cs" />
Note: See TracChangeset for help on using the changeset viewer.