- Timestamp:
- 06/09/10 16:29:02 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Compact/DoubleList2XmlSerializer.cs
r3742 r3913 23 23 using System.Collections.Generic; 24 24 using System; 25 using System.Linq; 25 26 using HeuristicLab.Persistence.Core; 26 27 using HeuristicLab.Persistence.Default.Xml.Primitive; 28 using System.Text; 27 29 28 30 namespace HeuristicLab.Persistence.Default.Xml.Compact { 29 31 30 internal sealed class DoubleList2XmlSerializer : NumberEnumeration2XmlSerializerBase<List<double>> {32 internal sealed class DoubleList2XmlSerializer : CompactXmlSerializerBase<List<double>> { 31 33 32 protected override void Add(IEnumerable enumeration, object o) { 33 ((List<double>)enumeration).Add((double)o); 34 private static readonly char[] separators = new char[] { ';' }; 35 36 public override XmlString Format(List<double> list) { 37 StringBuilder sb = new StringBuilder(); 38 foreach (var d in list) { 39 sb.Append(Double2XmlSerializer.FormatG17(d)).Append(';'); 40 } 41 return new XmlString(sb.ToString()); 34 42 } 35 43 36 protected override IEnumerable Instantiate() { 37 return new List<double>(); 44 public override List<double> Parse(XmlString data) { 45 try { 46 var values = data.Data.Split(separators, StringSplitOptions.RemoveEmptyEntries); 47 List<double> list = new List<double>(values.Length); 48 foreach (var value in values) { 49 list.Add(Double2XmlSerializer.ParseG17(value)); 50 } 51 return list; 52 } catch (InvalidCastException e) { 53 throw new PersistenceException("Invalid element data during reconstruction of List<double>.", e); 54 } catch (OverflowException e) { 55 throw new PersistenceException("Overflow during element parsing while trying to reconstruct List<double>.", e); 56 } 38 57 } 39 40 protected override string FormatValue(object o) {41 return Double2XmlSerializer.FormatG17((double)o);42 }43 44 protected override object ParseValue(string o) {45 return Double2XmlSerializer.ParseG17(o);46 }47 48 58 } 49 59 }
Note: See TracChangeset
for help on using the changeset viewer.