- Timestamp:
- 09/16/14 16:49:37 (10 years ago)
- Location:
- stable
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 10896,11352
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Persistence
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Persistence merged: 10896
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/Number2StringSerializer.cs
r11170 r11373 78 78 /// </returns> 79 79 public bool CanSerialize(Type type) { 80 return numberSerializerMap.ContainsKey( type);80 return numberSerializerMap.ContainsKey(Nullable.GetUnderlyingType(type) ?? type); 81 81 } 82 82 … … 90 90 /// </returns> 91 91 public string JustifyRejection(Type type) { 92 return string.Format("not a number type (one of {0})",92 return string.Format("not a (nullable) number type (one of {0})", 93 93 string.Join(", ", numberSerializers.Select(n => n.SourceType.Name).ToArray())); 94 94 } … … 100 100 /// <returns></returns> 101 101 public string Format(object obj) { 102 return ((XmlString)numberSerializerMap[obj.GetType()].Format(obj)).Data; 102 if (obj == null) return "null"; 103 Type type = obj.GetType(); 104 return ((XmlString)numberSerializerMap[Nullable.GetUnderlyingType(type) ?? type].Format(obj)).Data; 103 105 } 104 106 … … 110 112 /// <returns></returns> 111 113 public object Parse(string stringValue, Type type) { 114 if (stringValue == "null") return null; 112 115 try { 113 return numberSerializerMap[ type].Parse(new XmlString(stringValue));116 return numberSerializerMap[Nullable.GetUnderlyingType(type) ?? type].Parse(new XmlString(stringValue)); 114 117 } 115 118 catch (FormatException e) { -
stable/HeuristicLab.Tests
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Tests merged: 10896,11352
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Tests/HeuristicLab.Persistence-3.3/UseCases.cs
r11170 r11373 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 24 24 using System.Collections.Generic; 25 25 using System.Drawing; 26 using System.Globalization; 26 27 using System.IO; 27 28 using System.Linq; … … 1441 1442 } 1442 1443 1444 [TestMethod] 1445 [TestCategory("Persistence")] 1446 [TestProperty("Time", "short")] 1447 public void TestSpecialCharacters() { 1448 var s = "abc" + "\x15" + "def"; 1449 XmlGenerator.Serialize(s, tempFile); 1450 var newS = XmlParser.Deserialize(tempFile); 1451 Assert.AreEqual(s, newS); 1452 } 1453 1454 [TestMethod] 1455 [TestCategory("Persistence")] 1456 [TestProperty("Time", "short")] 1457 public void TestByteArray() { 1458 var b = new byte[3]; 1459 b[0] = 0; 1460 b[1] = 200; 1461 b[2] = byte.MaxValue; 1462 XmlGenerator.Serialize(b, tempFile); 1463 var newB = (byte[]) XmlParser.Deserialize(tempFile); 1464 CollectionAssert.AreEqual(b, newB); 1465 } 1466 1467 [TestMethod] 1468 [TestCategory("Persistence")] 1469 [TestProperty("Time", "short")] 1470 public void TestOptionalNumberEnumerable() { 1471 var values = new List<double?> {0, null, double.NaN, double.PositiveInfinity, double.MaxValue, 1}; 1472 XmlGenerator.Serialize(values, tempFile); 1473 var newValues = (List<double?>) XmlParser.Deserialize(tempFile); 1474 CollectionAssert.AreEqual(values, newValues); 1475 } 1476 1477 [TestMethod] 1478 [TestCategory("Persistence")] 1479 [TestProperty("Time", "short")] 1480 public void TestOptionalDateTimeEnumerable() { 1481 var values = new List<DateTime?> { DateTime.MinValue, null, DateTime.Now, DateTime.Now.Add(TimeSpan.FromDays(1)), 1482 DateTime.ParseExact("10.09.2014 12:21", "dd.MM.yyyy hh:mm", CultureInfo.InvariantCulture), DateTime.MaxValue}; 1483 XmlGenerator.Serialize(values, tempFile); 1484 var newValues = (List<DateTime?>) XmlParser.Deserialize(tempFile); 1485 CollectionAssert.AreEqual(values, newValues); 1486 } 1487 1488 [TestMethod] 1489 [TestCategory("Persistence")] 1490 [TestProperty("Time", "short")] 1491 public void TestStringEnumerable() { 1492 var values = new List<string> {"", null, "s", "string", string.Empty, "123", "<![CDATA[nice]]>", "<![CDATA[nasty unterminated"}; 1493 XmlGenerator.Serialize(values, tempFile); 1494 var newValues = (List<String>) XmlParser.Deserialize(tempFile); 1495 CollectionAssert.AreEqual(values, newValues); 1496 } 1497 1498 [TestMethod] 1499 [TestCategory("Persistence")] 1500 [TestProperty("Time", "short")] 1501 public void TestUnicodeCharArray() { 1502 var s = Encoding.UTF8.GetChars(new byte[] {0, 1, 2, 03, 04, 05, 06, 07, 08, 09, 0xa, 0xb}); 1503 XmlGenerator.Serialize(s, tempFile); 1504 var newS = (char[])XmlParser.Deserialize(tempFile); 1505 CollectionAssert.AreEqual(s, newS); 1506 } 1507 1508 [TestMethod] 1509 [TestCategory("Persistence")] 1510 [TestProperty("Time", "short")] 1511 public void TestUnicode() { 1512 var s = Encoding.UTF8.GetString(new byte[] {0, 1, 2, 03, 04, 05, 06, 07, 08, 09, 0xa, 0xb}); 1513 XmlGenerator.Serialize(s, tempFile); 1514 var newS = XmlParser.Deserialize(tempFile); 1515 Assert.AreEqual(s, newS); 1516 } 1517 1518 1443 1519 [ClassInitialize] 1444 1520 public static void Initialize(TestContext testContext) {
Note: See TracChangeset
for help on using the changeset viewer.