Index: /trunk/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/Number2StringSerializer.cs
===================================================================
--- /trunk/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/Number2StringSerializer.cs (revision 10895)
+++ /trunk/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/Number2StringSerializer.cs (revision 10896)
@@ -78,5 +78,5 @@
///
public bool CanSerialize(Type type) {
- return numberSerializerMap.ContainsKey(type);
+ return numberSerializerMap.ContainsKey(Nullable.GetUnderlyingType(type) ?? type);
}
@@ -90,5 +90,5 @@
///
public string JustifyRejection(Type type) {
- return string.Format("not a number type (one of {0})",
+ return string.Format("not a (nullable) number type (one of {0})",
string.Join(", ", numberSerializers.Select(n => n.SourceType.Name).ToArray()));
}
@@ -100,5 +100,7 @@
///
public string Format(object obj) {
- return ((XmlString)numberSerializerMap[obj.GetType()].Format(obj)).Data;
+ if (obj == null) return "null";
+ Type type = obj.GetType();
+ return ((XmlString)numberSerializerMap[Nullable.GetUnderlyingType(type) ?? type].Format(obj)).Data;
}
@@ -110,6 +112,7 @@
///
public object Parse(string stringValue, Type type) {
+ if (stringValue == "null") return null;
try {
- return numberSerializerMap[type].Parse(new XmlString(stringValue));
+ return numberSerializerMap[Nullable.GetUnderlyingType(type) ?? type].Parse(new XmlString(stringValue));
}
catch (FormatException e) {
Index: /trunk/sources/HeuristicLab.Tests/HeuristicLab.Persistence-3.3/UseCases.cs
===================================================================
--- /trunk/sources/HeuristicLab.Tests/HeuristicLab.Persistence-3.3/UseCases.cs (revision 10895)
+++ /trunk/sources/HeuristicLab.Tests/HeuristicLab.Persistence-3.3/UseCases.cs (revision 10896)
@@ -1464,4 +1464,14 @@
}
+ [TestMethod]
+ [TestCategory("Persistence")]
+ [TestProperty("Time", "short")]
+ public void TestOptionalNumberEnumerable() {
+ var values = new List {0, null, double.NaN, double.PositiveInfinity, double.MaxValue, 1};
+ XmlGenerator.Serialize(values, tempFile);
+ var newValues = (List) XmlParser.Deserialize(tempFile);
+ CollectionAssert.AreEqual(values, newValues);
+ }
+
[ClassInitialize]