Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1644


Ignore:
Timestamp:
04/23/09 17:41:55 (16 years ago)
Author:
epitzer
Message:

support for default disabled decomposers, re-activate number2string decomposer with negative priority. (#548)

Location:
trunk/sources/HeuristicLab.Persistence
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Persistence/3.3/Core/ConfigurationService.cs

    r1625 r1644  
    11using System;
    22using System.IO;
     3using System.Linq;
    34using System.Collections.Generic;
    45using System.Reflection;
     
    159160          format.SerialDataType.VersionInvariantName()));
    160161      }
    161       return new Configuration(format, formatterConfig, Decomposers);
     162      return new Configuration(format, formatterConfig, Decomposers.Where((d) => d.Priority > 0));
    162163    }
    163164
  • trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers/CompactNumberArray2StringDecomposer.cs

    r1625 r1644  
    1717    }
    1818
    19     private static readonly Number2StringConverter numberConverter =
    20       new Number2StringConverter();
     19    private static readonly Number2StringDecomposer numberConverter =
     20      new Number2StringDecomposer();
    2121
    2222    public bool CanDecompose(Type type) {
  • trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers/Number2StringConverter.cs

    r1625 r1644  
    99namespace HeuristicLab.Persistence.Default.Decomposers {
    1010
    11   public class Number2StringConverter {
     11  public class Number2StringDecomposer : IDecomposer {
    1212
    1313    private static readonly List<Type> numberTypes =
     
    2929    private static readonly Dictionary<Type, MethodInfo> numberParsers;
    3030
    31     static Number2StringConverter() {
     31    static Number2StringDecomposer() {
    3232      numberParsers = new Dictionary<Type, MethodInfo>();
    3333      foreach (var type in numberTypes) {
     
    6565    }
    6666
     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
    67102  }
    68103
  • trunk/sources/HeuristicLab.Persistence/3.3/Default/Decomposers/NumberEnumerable2StringDecomposer.cs

    r1625 r1644  
    1717    }
    1818
    19     private static readonly Number2StringConverter numberConverter =
    20       new Number2StringConverter();
     19    private static readonly Number2StringDecomposer numberConverter =
     20      new Number2StringDecomposer();
    2121
    2222    private static readonly Dictionary<Type, Type> interfaceCache = new Dictionary<Type, Type>();
  • trunk/sources/HeuristicLab.Persistence/UnitTests/UseCases.cs

    r1625 r1644  
    1111using System.Reflection;
    1212using HeuristicLab.Persistence.Default.Decomposers.Storable;
     13using HeuristicLab.Persistence.Interfaces;
     14using HeuristicLab.Persistence.Default.Xml.Primitive;
     15using HeuristicLab.Persistence.Default.Decomposers;
    1316
    1417namespace HeuristicLab.Persistence.UnitTest {
     
    312315    }
    313316
     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
    314330
    315331    [ClassInitialize]
Note: See TracChangeset for help on using the changeset viewer.