Changeset 1705
- Timestamp:
- 04/29/09 15:32:59 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.Persistence
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers/DictionaryDecomposer.cs
r1625 r1705 5 5 using System.Collections.Generic; 6 6 using HeuristicLab.Persistence.Default.Decomposers.Storable; 7 using HeuristicLab.Persistence.Auxiliary; 7 8 8 9 namespace HeuristicLab.Persistence.Default.Decomposers { … … 17 18 18 19 public bool CanDecompose(Type type) { 19 return type.GetInterface(typeof(IDictionary).FullName) != null; 20 return ReflectionTools.HasDefaultConstructor(type) && 21 type.GetInterface(typeof(IDictionary).FullName) != null; 20 22 } 21 23 … … 54 56 } catch (ArgumentException e) { 55 57 throw new PersistenceException("Duplicate dictionary key.", e); 56 } 58 } 57 59 } 58 60 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers/EnumerableDecomposer.cs
r1683 r1705 6 6 using System.Collections.Generic; 7 7 using HeuristicLab.Persistence.Default.Decomposers.Storable; 8 using HeuristicLab.Persistence.Auxiliary; 8 9 9 10 namespace HeuristicLab.Persistence.Default.Decomposers { … … 19 20 public bool CanDecompose(Type type) { 20 21 return 22 ReflectionTools.HasDefaultConstructor(type) && 21 23 type.GetInterface(typeof(IEnumerable).FullName) != null && 22 24 type.GetMethod("Add") != null && -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers/NumberEnumerable2StringDecomposer.cs
r1644 r1705 7 7 using System.Text; 8 8 using HeuristicLab.Persistence.Default.Decomposers.Storable; 9 using HeuristicLab.Persistence.Auxiliary; 9 10 10 11 namespace HeuristicLab.Persistence.Default.Decomposers { … … 54 55 public bool CanDecompose(Type type) { 55 56 return 57 ReflectionTools.HasDefaultConstructor(type) && 56 58 ImplementsGenericEnumerable(type) && 57 59 HasAddMethod(type); -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers/Storable/StorableDecomposer.cs
r1679 r1705 4 4 using HeuristicLab.Persistence.Interfaces; 5 5 using HeuristicLab.Persistence.Core; 6 using System.Reflection; 7 using HeuristicLab.Persistence.Auxiliary; 6 8 7 9 namespace HeuristicLab.Persistence.Default.Decomposers.Storable { … … 15 17 16 18 public bool CanDecompose(Type type) { 17 return StorableAttribute.GetStorableMembers(type, false).Count() > 0 || 18 EmptyStorableClassAttribute.IsEmptyStorable(type); 19 return ReflectionTools.HasDefaultConstructor(type) && 20 (StorableAttribute.GetStorableMembers(type, false).Count() > 0 || 21 EmptyStorableClassAttribute.IsEmptyStorable(type)); 19 22 20 23 } … … 26 29 public IEnumerable<Tag> Decompose(object obj) { 27 30 foreach (var mapping in StorableAttribute.GetStorableAccessors(obj)) { 28 yield return new Tag(mapping.Value.Name ?? mapping.Key, mapping.Value.Get()); 31 yield return new Tag(mapping.Value.Name ?? mapping.Key, mapping.Value.Get()); 29 32 } 30 33 } -
trunk/sources/HeuristicLab.Persistence/UnitTests/UseCases.cs
r1701 r1705 38 38 } 39 39 40 public class NonDefaultConstructorClass { 41 [Storable] 42 int value; 43 public NonDefaultConstructorClass(int value) { 44 this.value = value; 45 } 46 } 47 40 48 public class IntWrapper { 41 49 … … 100 108 [Storable] 101 109 public int[] i = new[] { 3, 4, 5, 6 }; 102 [Storable(Name ="Test String")]110 [Storable(Name = "Test String")] 103 111 public string s; 104 112 [Storable] … … 178 186 179 187 [TestCleanup()] 180 public void ClearTempFile() { 188 public void ClearTempFile() { 181 189 StreamReader reader = new StreamReader(tempFile); 182 190 string s = reader.ReadToEnd(); … … 210 218 Assert.AreEqual( 211 219 DebugStringGenerator.Serialize(r), 212 DebugStringGenerator.Serialize(newR)); 220 DebugStringGenerator.Serialize(newR)); 213 221 Assert.AreSame(newR, newR.selfReferences[0]); 214 222 Assert.AreNotSame(r, newR); … … 223 231 Assert.AreEqual(r.intList[0], 9); 224 232 Assert.AreEqual(r.intList[1], 8); 225 Assert.AreEqual(r.intList[2], 7); 233 Assert.AreEqual(r.intList[2], 7); 226 234 Assert.AreEqual(r.multiDimArray[0, 0], 5); 227 235 Assert.AreEqual(r.multiDimArray[0, 1], 4); … … 231 239 Assert.AreEqual(r.multiDimArray[1, 2], 6); 232 240 Assert.IsFalse(r.boolean); 233 Assert.IsTrue((DateTime.Now - r.dateTime).TotalSeconds < 10); 241 Assert.IsTrue((DateTime.Now - r.dateTime).TotalSeconds < 10); 234 242 Assert.AreEqual(r.kvp.Key, "string key"); 235 243 Assert.AreEqual(r.kvp.Value, 321); … … 486 494 } 487 495 496 [TestMethod] 497 public void NonDefaultConstructorTest() { 498 NonDefaultConstructorClass c = new NonDefaultConstructorClass(1); 499 try { 500 XmlGenerator.Serialize(c, tempFile); 501 Assert.Fail("Exception not thrown"); 502 } catch (PersistenceException) { 503 } 504 } 505 488 506 [ClassInitialize] 489 507 public static void Initialize(TestContext testContext) {
Note: See TracChangeset
for help on using the changeset viewer.