Changeset 1644
- Timestamp:
- 04/23/09 17:41:55 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.Persistence
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Persistence/3.3/Core/ConfigurationService.cs
r1625 r1644 1 1 using System; 2 2 using System.IO; 3 using System.Linq; 3 4 using System.Collections.Generic; 4 5 using System.Reflection; … … 159 160 format.SerialDataType.VersionInvariantName())); 160 161 } 161 return new Configuration(format, formatterConfig, Decomposers );162 return new Configuration(format, formatterConfig, Decomposers.Where((d) => d.Priority > 0)); 162 163 } 163 164 -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers/CompactNumberArray2StringDecomposer.cs
r1625 r1644 17 17 } 18 18 19 private static readonly Number2String Converter numberConverter =20 new Number2String Converter();19 private static readonly Number2StringDecomposer numberConverter = 20 new Number2StringDecomposer(); 21 21 22 22 public bool CanDecompose(Type type) { -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers/Number2StringConverter.cs
r1625 r1644 9 9 namespace HeuristicLab.Persistence.Default.Decomposers { 10 10 11 public class Number2String Converter {11 public class Number2StringDecomposer : IDecomposer { 12 12 13 13 private static readonly List<Type> numberTypes = … … 29 29 private static readonly Dictionary<Type, MethodInfo> numberParsers; 30 30 31 static Number2String Converter() {31 static Number2StringDecomposer() { 32 32 numberParsers = new Dictionary<Type, MethodInfo>(); 33 33 foreach (var type in numberTypes) { … … 65 65 } 66 66 67 68 #region IDecomposer Members 69 70 public int Priority { 71 get { return -100; } 72 } 73 74 public IEnumerable<Tag> CreateMetaInfo(object obj) { 75 yield return new Tag(Format(obj)); 76 } 77 78 public IEnumerable<Tag> Decompose(object obj) { 79 // numbers are composed just of meta info 80 return new Tag[] { }; 81 } 82 83 public object CreateInstance(Type type, IEnumerable<Tag> metaInfo) { 84 var it = metaInfo.GetEnumerator(); 85 try { 86 it.MoveNext(); 87 return Parse((string)it.Current.Value, type); 88 } catch (InvalidOperationException e) { 89 throw new PersistenceException( 90 String.Format("Insufficient meta information to reconstruct number of type {0}.", 91 type.VersionInvariantName()), e); 92 } catch (InvalidCastException e) { 93 throw new PersistenceException("Invalid meta information element type", e); 94 } 95 } 96 97 public void Populate(object instance, IEnumerable<Tag> tags, Type type) { 98 // numbers are composed just of meta info, no need to populate 99 } 100 101 #endregion 67 102 } 68 103 -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers/NumberEnumerable2StringDecomposer.cs
r1625 r1644 17 17 } 18 18 19 private static readonly Number2String Converter numberConverter =20 new Number2String Converter();19 private static readonly Number2StringDecomposer numberConverter = 20 new Number2StringDecomposer(); 21 21 22 22 private static readonly Dictionary<Type, Type> interfaceCache = new Dictionary<Type, Type>(); -
trunk/sources/HeuristicLab.Persistence/UnitTests/UseCases.cs
r1625 r1644 11 11 using System.Reflection; 12 12 using HeuristicLab.Persistence.Default.Decomposers.Storable; 13 using HeuristicLab.Persistence.Interfaces; 14 using HeuristicLab.Persistence.Default.Xml.Primitive; 15 using HeuristicLab.Persistence.Default.Decomposers; 13 16 14 17 namespace HeuristicLab.Persistence.UnitTest { … … 312 315 } 313 316 317 [TestMethod] 318 public void Number2StringDecomposer() { 319 PrimitivesTest sdt = new PrimitivesTest(); 320 XmlGenerator.Serialize(sdt, tempFile, 321 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); 325 Assert.AreEqual( 326 DebugStringGenerator.Serialize(sdt), 327 DebugStringGenerator.Serialize(o)); 328 } 329 314 330 315 331 [ClassInitialize]
Note: See TracChangeset
for help on using the changeset viewer.