Changeset 1652
- Timestamp:
- 04/24/09 13:51:57 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.Persistence
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Persistence/3.3/Core/Serializer.cs
r1625 r1652 2 2 using System.Collections; 3 3 using System; 4 using System.Linq; 4 5 using HeuristicLab.Persistence.Interfaces; 5 6 using HeuristicLab.Persistence.Core.Tokens; 6 7 using HeuristicLab.Persistence.Default.Decomposers.Storable; 8 using System.Text; 7 9 8 10 namespace HeuristicLab.Persistence.Core { … … 76 78 throw new PersistenceException( 77 79 String.Format( 78 "No suitable method for serializing values of type \"{0}\" found.", 79 value.GetType().VersionInvariantName())); 80 "No suitable method for serializing values of type \"{0}\" found\r\n" + 81 "Formatters:\r\n{1}\r\n" + 82 "Decomposers:\r\n{2}", 83 value.GetType().VersionInvariantName(), 84 string.Join("\r\n", configuration.Formatters.Select(f => f.GetType().VersionInvariantName()).ToArray()), 85 string.Join("\r\n", configuration.Decomposers.Select(d => d.GetType().VersionInvariantName()).ToArray()) 86 )); 87 80 88 } 81 89 -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers/Storable/EmptyStorableClassAttribute.cs
r1623 r1652 17 17 if (emptyTypeInfo.ContainsKey(type)) 18 18 return emptyTypeInfo[type]; 19 if (type == typeof(object)) { 20 return true; 21 } 19 22 foreach (var attribute in type.GetCustomAttributes(false)) { 20 23 EmptyStorableClassAttribute empty = attribute as EmptyStorableClassAttribute; -
trunk/sources/HeuristicLab.Persistence/3.3/HeuristicLab.Persistence-3.3.csproj
r1625 r1652 95 95 <Compile Include="Core\Configuration.cs" /> 96 96 <Compile Include="Core\PersistenceException.cs" /> 97 <Compile Include="Default\DebugString\Formatters\Char2DebugStringFormatter.cs" /> 97 98 <Compile Include="Default\Decomposers\Number2StringConverter.cs" /> 98 99 <Compile Include="Default\Decomposers\Storable\EmptyStorableClassAttribute.cs" /> … … 137 138 <Compile Include="Default\Decomposers\Storable\DataMemberAccessor.cs" /> 138 139 <Compile Include="Default\Xml\Compact\IntList2XmlFormatter.cs" /> 140 <Compile Include="Default\Xml\Primitive\Char2XmlFormatter.cs" /> 139 141 <Compile Include="Default\Xml\XmlStringConstants.cs" /> 140 142 <Compile Include="Default\Xml\XmlString.cs" /> -
trunk/sources/HeuristicLab.Persistence/UnitTests/UseCases.cs
r1644 r1652 17 17 namespace HeuristicLab.Persistence.UnitTest { 18 18 19 public class PrimitivesTest {19 public class NumberTest { 20 20 [Storable] 21 21 private bool _bool = true; … … 36 36 [Storable] 37 37 private ulong _ulong = 123456; 38 } 39 40 public class PrimitivesTest : NumberTest { 41 [Storable] 42 private char c = 'e'; 38 43 [Storable] 39 44 private long[,] _long_array = … … 41 46 [Storable] 42 47 public List<int> list = new List<int> { 1, 2, 3, 4, 5 }; 48 [Storable] 49 private object o = new object(); 43 50 } 44 51 … … 132 139 r.dict.Add("three", 3); 133 140 r.myEnum = TestEnum.va1; 141 r.i = new[] { 7, 5, 6 }; 142 r.s = "new value"; 143 r.intArray = new ArrayList { 3, 2, 1 }; 144 r.intList = new List<int> { 9, 8, 7 }; 145 r.multiDimArray = new double[,] { { 5, 4, 3 }, { 1, 4, 6 } }; 146 r.boolean = false; 147 r.dateTime = DateTime.Now; 148 r.kvp = new KeyValuePair<string, int>("string key", 321); 149 r.uninitialized = null; 134 150 XmlGenerator.Serialize(r, tempFile); 135 151 object o = XmlParser.DeSerialize(tempFile); … … 140 156 Assert.AreSame(newR, newR.selfReferences[0]); 141 157 Assert.AreNotSame(r, newR); 158 Assert.AreEqual(r.myEnum, TestEnum.va1); 159 Assert.AreEqual(r.i[0], 7); 160 Assert.AreEqual(r.i[1], 5); 161 Assert.AreEqual(r.i[2], 6); 162 Assert.AreSame(r.s, "new value"); 163 Assert.AreEqual(r.intArray[0], 3); 164 Assert.AreEqual(r.intArray[1], 2); 165 Assert.AreEqual(r.intArray[2], 1); 166 Assert.AreEqual(r.intList[0], 9); 167 Assert.AreEqual(r.intList[1], 8); 168 Assert.AreEqual(r.intList[2], 7); 169 Assert.AreEqual(r.multiDimArray[0, 0], 5); 170 Assert.AreEqual(r.multiDimArray[0, 1], 4); 171 Assert.AreEqual(r.multiDimArray[0, 2], 3); 172 Assert.AreEqual(r.multiDimArray[1, 0], 1); 173 Assert.AreEqual(r.multiDimArray[1, 1], 4); 174 Assert.AreEqual(r.multiDimArray[1, 2], 6); 175 Assert.IsFalse(r.boolean); 176 Assert.IsTrue((DateTime.Now - r.dateTime).TotalSeconds < 10); 177 Assert.AreSame(r.kvp.Key, "string key"); 178 Assert.AreEqual(r.kvp.Value, 321); 179 Assert.IsNull(r.uninitialized); 142 180 } 143 181 … … 274 312 } 275 313 276 private string formatFullMemberName(MemberInfo mi) { 314 private string formatFullMemberName(MemberInfo mi) { 277 315 return new StringBuilder() 278 316 .Append(mi.DeclaringType.Assembly.GetName().Name) … … 292 330 foreach (Assembly a in AppDomain.CurrentDomain.GetAssemblies()) { 293 331 if (!a.GetName().Name.StartsWith("HeuristicLab")) 294 continue; 332 continue; 295 333 foreach (Type t in a.GetTypes()) { 296 334 foreach (MemberInfo mi in t.GetMembers(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static)) { … … 304 342 !mi.Name.StartsWith("set_") && 305 343 !mi.Name.StartsWith("add_") && 306 !mi.Name.StartsWith("remove_") 344 !mi.Name.StartsWith("remove_")) 307 345 lowerCaseMethodNames.Add(formatFullMemberName(mi)); 308 346 } … … 317 355 [TestMethod] 318 356 public void Number2StringDecomposer() { 319 PrimitivesTest sdt = new PrimitivesTest();357 NumberTest sdt = new NumberTest(); 320 358 XmlGenerator.Serialize(sdt, tempFile, 321 359 new Configuration(new XmlFormat(), 322 new Dictionary<Type, IFormatter> { { typeof(string), new String2XmlFormatter() } }, 323 new List<IDecomposer> { new Number2StringDecomposer() })); 324 object o = XmlParser.DeSerialize(tempFile); 360 new Dictionary<Type, IFormatter> { 361 { typeof(string), new String2XmlFormatter() } }, 362 new List<IDecomposer> { 363 new StorableDecomposer(), 364 new Number2StringDecomposer() })); 365 object o = XmlParser.DeSerialize(tempFile); 325 366 Assert.AreEqual( 326 367 DebugStringGenerator.Serialize(sdt),
Note: See TracChangeset
for help on using the changeset viewer.