Changeset 1679
- Timestamp:
- 04/27/09 18:36:06 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.Persistence
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Persistence/3.3/Core/Serializer.cs
r1652 r1679 28 28 } else { 29 29 IDecomposer d = configuration.GetDecomposer(pair.Key); 30 if (d != null) 31 serializer = d.GetType().VersionInvariantName(); 30 serializer = d.GetType().VersionInvariantName(); 32 31 } 33 32 result.Add(new TypeMapping(pair.Value, pair.Key.VersionInvariantName(), serializer)); -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers/EnumerableDecomposer.cs
r1625 r1679 53 53 } 54 54 } 55 56 57 [EmptyStorableClass] 58 public class StackDecomposer : IDecomposer { 59 60 public int Priority { 61 get { return 100; } 62 } 63 64 65 public bool CanDecompose(Type type) { 66 return type.IsGenericType && 67 type.GetGenericTypeDefinition() == typeof(Stack<>); 68 } 69 70 public IEnumerable<Tag> CreateMetaInfo(object o) { 71 return new Tag[] { }; 72 } 73 74 public IEnumerable<Tag> Decompose(object obj) { 75 foreach (object o in (IEnumerable)obj) { 76 yield return new Tag(null, o); 77 } 78 } 79 80 public object CreateInstance(Type type, IEnumerable<Tag> metaInfo) { 81 return Activator.CreateInstance(type, true); 82 } 83 84 public void Populate(object instance, IEnumerable<Tag> tags, Type type) { 85 MethodInfo addMethod = type.GetMethod("Push"); 86 try { 87 foreach (var tag in tags) 88 addMethod.Invoke(instance, new[] { tag.Value }); 89 } catch (Exception e) { 90 throw new PersistenceException("Exception caught while trying to populate enumerable.", e); 91 } 92 } 93 } 55 94 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers/Storable/StorableDecomposer.cs
r1623 r1679 26 26 public IEnumerable<Tag> Decompose(object obj) { 27 27 foreach (var mapping in StorableAttribute.GetStorableAccessors(obj)) { 28 yield return new Tag(mapping. Key, mapping.Value.Get());28 yield return new Tag(mapping.Value.Name ?? mapping.Key, mapping.Value.Get()); 29 29 } 30 30 } … … 41 41 } 42 42 foreach (var mapping in StorableAttribute.GetStorableAccessors(instance)) { 43 if (memberDict.ContainsKey(mapping.Key)) { 44 mapping.Value.Set(memberDict[mapping.Key].Value); 43 string name = mapping.Value.Name ?? mapping.Key; 44 if (memberDict.ContainsKey(name)) { 45 mapping.Value.Set(memberDict[name].Value); 45 46 } else if (mapping.Value.DefaultValue != null) { 46 47 mapping.Value.Set(mapping.Value.DefaultValue); -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/String2XmlFormatter.cs
r1659 r1679 5 5 using System.Text.RegularExpressions; 6 6 using HeuristicLab.Persistence.Default.Decomposers.Storable; 7 using System.Globalization; 7 8 8 9 9 10 namespace HeuristicLab.Persistence.Default.Xml.Primitive { 11 12 [EmptyStorableClass] 13 public class TimeSpan2XmlFormatter : PrimitiveXmlFormatterBase<TimeSpan> { 14 15 public override XmlString Format(TimeSpan o) { 16 return new XmlString(o.ToString()); 17 } 18 19 public override TimeSpan Parse(XmlString t) { 20 try { 21 return TimeSpan.Parse(t.Data); 22 } catch (FormatException x) { 23 throw new PersistenceException("Cannot parse TimeSpan string representation.", x); 24 } catch (OverflowException x) { 25 throw new PersistenceException("Overflow during TimeSpan parsing.", x); 26 } 27 } 28 } 29 30 [EmptyStorableClass] 31 public class Guid2XmlFormatter : PrimitiveXmlFormatterBase<Guid> { 32 33 public override XmlString Format(Guid o) { 34 return new XmlString(o.ToString("D", CultureInfo.InvariantCulture)); 35 } 36 37 public override Guid Parse(XmlString t) { 38 try { 39 return new Guid(t.Data); 40 } catch (FormatException x) { 41 throw new PersistenceException("Cannot parse Guid string representation.", x); 42 } catch (OverflowException x) { 43 throw new PersistenceException("Overflow during Guid parsing.", x); 44 } 45 } 46 } 10 47 11 48 [EmptyStorableClass] -
trunk/sources/HeuristicLab.Persistence/UnitTests/UseCases.cs
r1654 r1679 62 62 [Storable] 63 63 public int[] i = new[] { 3, 4, 5, 6 }; 64 [Storable ]64 [Storable(Name="Test String")] 65 65 public string s; 66 66 [Storable] … … 126 126 127 127 [TestCleanup()] 128 public void ClearTempFile() { 128 public void ClearTempFile() { 129 129 File.Delete(tempFile); 130 130 }
Note: See TracChangeset
for help on using the changeset viewer.