Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1312 for branches


Ignore:
Timestamp:
03/09/09 12:41:36 (16 years ago)
Author:
epitzer
Message:

Serialization of double values. (#506)

Location:
branches/New Persistence Exploration/Persistence/Persistence
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/New Persistence Exploration/Persistence/Persistence/NewSerializationTest.cs

    r1281 r1312  
    2121    [Storable]
    2222    public List<Root> selfReferences;
    23 
    2423  }
    2524
     
    4342      IPrimitiveSerializer[] serializers = {
    4443          new String2XMLSerializer(),
    45           new Int2XMLSerializer()};
     44          new Int2XMLSerializer(),
     45          new Double2XmlSerializer()};
    4646      Serializer s = new Serializer(r, serializers);
    4747      Persistence.XmlFormatter xmlFormatter = new Persistence.XmlFormatter();
     
    5555      XmlParser parser = new XmlParser(new StreamReader("test.xml"));
    5656      DeSerializer deSerializer = new DeSerializer(
    57         new IPrimitiveSerializer[] { new Int2XMLSerializer(), new String2XMLSerializer() },
    58         new ICustomSerializer[] { new ArraySerializer(), new EnumerableSerializer() });
     57        new IPrimitiveSerializer[] {
     58          new Int2XMLSerializer(),
     59          new String2XMLSerializer(),
     60          new Double2XmlSerializer(),
     61        },
     62        new ICustomSerializer[] {
     63          new ArraySerializer(),
     64          new EnumerableSerializer() });
    5965      object o = deSerializer.DeSerialize(parser);
    6066      Console.Out.WriteLine(Util.AutoFormat(o, true));
  • branches/New Persistence Exploration/Persistence/Persistence/PrimitiveSerializers.cs

    r1280 r1312  
    11using System;
    22using System.Text;
     3using System.Globalization;
    34namespace Persistence {
    45
     
    2627    }
    2728  }
    28 
    2929  public class Int2XMLSerializer : IPrimitiveSerializer {
    3030    public Type Type { get { return typeof(int); } }
     
    3636    }
    3737  }
     38  public class Double2XmlSerializer : IPrimitiveSerializer {   
     39    public Type Type { get { return typeof(double); } }       
     40    public object Serialize(object o) {
     41      return ((double)o).ToString("r", CultureInfo.InvariantCulture);     
     42    }
     43    public object DeSerialize(object o) {
     44      return double.Parse((string)o, CultureInfo.InvariantCulture);
     45    }
     46  }
    3847}
Note: See TracChangeset for help on using the changeset viewer.