Changeset 15857


Ignore:
Timestamp:
03/23/18 14:38:14 (15 months ago)
Author:
jkarder
Message:

#2520: worked on conversions

Location:
branches/PersistenceReintegration
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/PersistenceReintegration/HeuristicLab.Persistence/4.0/Core/StaticCache.cs

    r15529 r15857  
    166166    }
    167167
    168     // mainly for testing
    169     public void DeregisterType(Guid guid) {
    170       lock (locker) {
    171         type2Guid.Remove(guid2Type[guid]);
    172         guid2Type.Remove(guid);
    173       }
    174     }
    175 
    176168    public ITransformer GetTransformer(Guid guid) {
    177169      return guid2Transformer[guid];
     
    208200      return Enumerable.Empty<MethodInfo>();
    209201    }
     202
     203    public IEnumerable<MethodInfo> GetStorableConversions(IList<Tuple<Guid, uint>> typeChain) {
     204      foreach (var type in typeChain) {
     205        var conversionMethod = (from methodInfo in GetStorableConversions(type.Item1)
     206                                let attrib = StorableConversionAttribute.GetStorableConversionAttribute(methodInfo)
     207                                where attrib.Version == type.Item2 && (attrib.Dependencies == null ||
     208                                  attrib.Dependencies.All(x => typeChain.Any(y => y.Item1 == Guid.Parse(x.Key) && y.Item2 == x.Value)))
     209                                select methodInfo).SingleOrDefault();
     210        if (conversionMethod != null)
     211          yield return conversionMethod;
     212      }
     213    }
    210214  }
    211215}
  • branches/PersistenceReintegration/HeuristicLab.Persistence/4.0/Core/StorableConversionAttribute.cs

    r15529 r15857  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using System.Reflection;
    2425
     
    2829    public Guid Guid { get; private set; }
    2930    public uint Version { get; private set; }
     31    public IDictionary<string, uint> Dependencies { get; private set; }
    3032
    31     public StorableConversionAttribute(string guid, uint version) {
     33    public StorableConversionAttribute(string guid, uint version = 1u)
     34      : this(guid, version, null) { }
     35    public StorableConversionAttribute(string guid, uint version = 1u, string baseGuid = "", uint baseVersion = 0u)
     36      : this(guid, version, string.IsNullOrEmpty(baseGuid) ? null : new Dictionary<string, uint> { { baseGuid, baseVersion } }) { }
     37
     38    public StorableConversionAttribute(string guid, uint version = 1u, IDictionary<string, uint> dependencies = null) {
    3239      this.Guid = new Guid(guid);
    3340      this.Version = version;
     41      this.Dependencies = dependencies;
    3442    }
    3543
     
    4755      return GetStorableConversionAttribute(mi).Version;
    4856    }
     57    public static IDictionary<string, uint> GetDependencies(MethodInfo mi) {
     58      return GetStorableConversionAttribute(mi).Dependencies;
     59    }
    4960  }
    5061}
  • branches/PersistenceReintegration/HeuristicLab.Persistence/4.0/Transformers/Transformers.cs

    r15529 r15857  
    848848        typeVersions.Add(Tuple.Create(Guid.Parse(mapper.GetString(parentTypeVersions[i])), parentTypeVersions[i + 1]));
    849849
    850       var originalType = type;
    851       var originalTypeInfo = typeInfo;
    852 
    853       foreach (var entry in typeVersions) {
    854         var guid = entry.Item1;
    855         var version = entry.Item2;
    856 
    857         var conversionMethods = (from methodInfo in Mapper.StaticCache.GetStorableConversions(guid)
    858                                  let attrib = StorableConversionAttribute.GetStorableConversionAttribute(methodInfo)
    859                                  where attrib.Version >= version
    860                                  orderby attrib.Version
    861                                  select methodInfo).ToList();
    862 
    863         uint targetVersion;
    864 
    865         try {
    866           type = Mapper.StaticCache.GetType(guid);
    867           typeInfo = Mapper.StaticCache.GetTypeInfo(type);
    868           targetVersion = typeInfo.StorableTypeAttribute.Version;
    869         } catch (KeyNotFoundException) {
    870           targetVersion = 0;
    871         }
    872 
    873         Dictionary<string, object> lastDict = new Dictionary<string, object>();
    874         foreach (var conversionMethod in conversionMethods) {
    875           if (StorableConversionAttribute.GetVersion(conversionMethod) != version)
    876             throw new PersistenceException(string.Format("No conversion method defined for type {0} version {1}", guid, version));
    877 
    878           lastDict = (Dictionary<string, object>)conversionMethod.Invoke(null, new object[] { dict });
    879           foreach (var kvp in lastDict) dict[kvp.Key] = kvp.Value;
    880 
    881           version++;
    882         }
    883 
    884         if (version < targetVersion)
    885           throw new PersistenceException(string.Format("Missing one or more conversion methods for type {0} version {1}", guid, version));
     850      while (true) {
     851        var applicableConversion = Mapper.StaticCache.GetStorableConversions(typeVersions).FirstOrDefault();
     852        if (applicableConversion == null) break;
     853
     854        Dictionary<string, object> newDict;
     855        List<Tuple<string, uint>> typeChain = null;
     856
     857        var conversionParameters = applicableConversion.GetParameters();
     858        if (conversionParameters.Length == 1) {
     859          newDict = (Dictionary<string, object>)applicableConversion.Invoke(null, new object[] { dict });
     860        } else if (conversionParameters.Length == 2) {
     861          var parameters = new object[] { dict, typeChain };
     862          newDict = (Dictionary<string, object>)applicableConversion.Invoke(null, parameters);
     863          typeChain = (List<Tuple<string, uint>>)parameters[1];
     864        } else throw new PersistenceException("Conversion method has an invalid signature.");
     865
     866        foreach (var kvp in newDict) dict[kvp.Key] = kvp.Value;
     867
     868        var convertedType = StorableConversionAttribute.GetGuid(applicableConversion);
     869        var convertedVersion = StorableConversionAttribute.GetVersion(applicableConversion);
     870
     871        var index = typeVersions.FindIndex(x => x.Item1 == convertedType);
     872        typeVersions.RemoveAt(index);
     873        typeVersions.Insert(index, Tuple.Create(convertedType, convertedVersion + 1));
     874
     875        if (typeChain != null && typeChain.Any()) {
     876          typeVersions.RemoveRange(index + 1, typeVersions.Count - (index + 1));
     877          typeVersions.AddRange(typeChain.Select(x => Tuple.Create(Guid.Parse(x.Item1), x.Item2)));
     878        }
    886879      }
    887880
    888881      var typeStack = new Stack<Tuple<Type, TypeInfo>>();
    889       type = originalType;
    890       typeInfo = originalTypeInfo;
    891882
    892883      while (StorableTypeAttribute.IsStorableType(type)) {
  • branches/PersistenceReintegration/HeuristicLab.Tests/HeuristicLab.Persistence-3.3/UseCases.cs

    r15018 r15857  
    3636using HeuristicLab.Persistence.Core.Tokens;
    3737using HeuristicLab.Persistence.Default.CompositeSerializers;
     38using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3839using HeuristicLab.Persistence.Default.DebugString;
    3940using HeuristicLab.Persistence.Default.Xml;
     
    4243using HeuristicLab.Tests;
    4344using Microsoft.VisualStudio.TestTools.UnitTesting;
    44 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    4545
    4646namespace HeuristicLab.Persistence.Tests {
     
    10301030      public int Value3 { get; private set; }
    10311031      public int Value4 { get; private set; }
     1032
    10321033      [StorableConstructor]
    10331034      public AllPropertiesStorable(bool isDeserializing) {
  • branches/PersistenceReintegration/HeuristicLab.Tests/HeuristicLab.Persistence-3.3/UseCasesPersistenceNew.cs

    r15529 r15857  
    285285    public int y { get; set; }
    286286  }
    287 
    288287  #endregion
    289288
     
    293292    #region Helpers
    294293    private string tempFile;
     294    private static Dictionary<Guid, Type> guid2Type;
     295    private static Dictionary<Type, Guid> type2Guid;
     296    private static Dictionary<Type, Persistence.TypeInfo> typeInfos;
     297    private static PropertyInfo guidPropertyInfo = typeof(StorableTypeAttribute).GetProperty("Guid");
     298
    295299
    296300    [ClassInitialize]
    297301    public static void Initialize(TestContext testContext) {
    298302      ConfigurationService.Instance.Reset();
     303
     304      var guid2TypeFieldInfo = typeof(StaticCache).GetField("guid2Type", BindingFlags.NonPublic | BindingFlags.Instance);
     305      var type2GuidFieldInfo = typeof(StaticCache).GetField("type2Guid", BindingFlags.NonPublic | BindingFlags.Instance);
     306      var typeInfosFieldInfo = typeof(StaticCache).GetField("typeInfos", BindingFlags.NonPublic | BindingFlags.Instance);
     307
     308      guid2Type = (Dictionary<Guid, Type>)guid2TypeFieldInfo.GetValue(Mapper.StaticCache);
     309      type2Guid = (Dictionary<Type, Guid>)type2GuidFieldInfo.GetValue(Mapper.StaticCache);
     310      typeInfos = (Dictionary<Type, Persistence.TypeInfo>)typeInfosFieldInfo.GetValue(Mapper.StaticCache);
    299311    }
    300312
     
    310322      reader.Close();
    311323      File.Delete(tempFile);
     324    }
     325
     326    public static void RegisterType(Guid guid, Type type) {
     327      Mapper.StaticCache.RegisterType(guid, type);
     328    }
     329
     330    public static void DeregisterType(Type type) {
     331      var typeInfo = GetTypeInfo(type);
     332      type2Guid.Remove(guid2Type[typeInfo.StorableTypeAttribute.Guid]);
     333      guid2Type.Remove(typeInfo.StorableTypeAttribute.Guid);
     334    }
     335
     336    public static Persistence.TypeInfo GetTypeInfo(Type type) {
     337      return Mapper.StaticCache.GetTypeInfo(type);
     338    }
     339
     340    public static void RemoveTypeInfo(Type type) {
     341      typeInfos.Remove(typeof(ConversionA));
     342    }
     343
     344    public static Guid GetTypeGuid(Type type) {
     345      var typeInfo = GetTypeInfo(type);
     346      return typeInfo.StorableTypeAttribute.Guid;
     347    }
     348
     349    public static void SetTypeGuid(Type type, Guid guid) {
     350      var typeInfo = GetTypeInfo(type);
     351      guidPropertyInfo.SetValue(typeInfo.StorableTypeAttribute, guid);
    312352    }
    313353    #endregion
     
    455495    #endregion
    456496
    457     #region Persistence 4.0 test methods
    458     [TestMethod]
    459     [TestCategory("Persistence4")]
     497    #region Persistence 4.0 Test methods
     498    [TestMethod]
     499    [TestCategory("PersistenceNew")]
    460500    [TestProperty("Time", "short")]
    461501    public void TestBool() {
     
    472512
    473513    [TestMethod]
    474     [TestCategory("Persistence4")]
     514    [TestCategory("PersistenceNew")]
    475515    [TestProperty("Time", "short")]
    476516    public void TestInt() {
     
    487527
    488528    [TestMethod]
    489     [TestCategory("Persistence4")]
     529    [TestCategory("PersistenceNew")]
    490530    [TestProperty("Time", "short")]
    491531    public void TestDouble() {
     
    503543
    504544    [TestMethod]
    505     [TestCategory("Persistence4")]
     545    [TestCategory("PersistenceNew")]
    506546    [TestProperty("Time", "short")]
    507547    public void TestFloat() {
     
    519559
    520560    [TestMethod]
    521     [TestCategory("Persistence4")]
     561    [TestCategory("PersistenceNew")]
    522562    [TestProperty("Time", "short")]
    523563    public void TestDecimal() {
     
    535575
    536576    [TestMethod]
    537     [TestCategory("Persistence4")]
     577    [TestCategory("PersistenceNew")]
    538578    [TestProperty("Time", "short")]
    539579    public void TestLong() {
     
    551591
    552592    [TestMethod]
    553     [TestCategory("Persistence4")]
     593    [TestCategory("PersistenceNew")]
    554594    [TestProperty("Time", "short")]
    555595    public void TestUInt() {
     
    567607
    568608    [TestMethod]
    569     [TestCategory("Persistence4")]
     609    [TestCategory("PersistenceNew")]
    570610    [TestProperty("Time", "short")]
    571611    public void TestShort() {
     
    583623
    584624    [TestMethod]
    585     [TestCategory("Persistence4")]
     625    [TestCategory("PersistenceNew")]
    586626    [TestProperty("Time", "short")]
    587627    public void TestByte() {
     
    599639
    600640    [TestMethod]
    601     [TestCategory("Persistence4")]
     641    [TestCategory("PersistenceNew")]
    602642    [TestProperty("Time", "short")]
    603643    public void TestEnumSimple() {
     
    615655
    616656    [TestMethod]
    617     [TestCategory("Persistence4")]
     657    [TestCategory("PersistenceNew")]
    618658    [TestProperty("Time", "short")]
    619659    public void TestEnumComplex() {
     
    630670
    631671    [TestMethod]
    632     [TestCategory("Persistence4")]
     672    [TestCategory("PersistenceNew")]
    633673    [TestProperty("Time", "short")]
    634674    public void TestType() {
     
    645685
    646686    [TestMethod]
    647     [TestCategory("Persistence4")]
     687    [TestCategory("PersistenceNew")]
    648688    [TestProperty("Time", "short")]
    649689    public void TestBytes() {
     
    661701
    662702    [TestMethod]
    663     [TestCategory("Persistence4")]
     703    [TestCategory("PersistenceNew")]
    664704    [TestProperty("Time", "short")]
    665705    public void TestSBytes() {
     
    677717
    678718    [TestMethod]
    679     [TestCategory("Persistence4")]
     719    [TestCategory("PersistenceNew")]
    680720    [TestProperty("Time", "short")]
    681721    public void TestChars() {
     
    693733
    694734    [TestMethod]
    695     [TestCategory("Persistence4")]
     735    [TestCategory("PersistenceNew")]
    696736    [TestProperty("Time", "short")]
    697737    public void TestShorts() {
     
    709749
    710750    [TestMethod]
    711     [TestCategory("Persistence4")]
     751    [TestCategory("PersistenceNew")]
    712752    [TestProperty("Time", "short")]
    713753    public void TestUShorts() {
     
    725765
    726766    [TestMethod]
    727     [TestCategory("Persistence4")]
     767    [TestCategory("PersistenceNew")]
    728768    [TestProperty("Time", "short")]
    729769    public void TestString() {
     
    740780
    741781    [TestMethod]
    742     [TestCategory("Persistence4")]
     782    [TestCategory("PersistenceNew")]
    743783    [TestProperty("Time", "short")]
    744784    public void TestColor() {
     
    755795
    756796    [TestMethod]
    757     [TestCategory("Persistence4")]
     797    [TestCategory("PersistenceNew")]
    758798    [TestProperty("Time", "short")]
    759799    public void TestPoint() {
     
    771811
    772812    [TestMethod]
    773     [TestCategory("Persistence4")]
     813    [TestCategory("PersistenceNew")]
    774814    [TestProperty("Time", "short")]
    775815    public void TestBoolArray() {
     
    788828
    789829    [TestMethod]
    790     [TestCategory("Persistence4")]
     830    [TestCategory("PersistenceNew")]
    791831    [TestProperty("Time", "short")]
    792832    public void TestIntArray() {
     
    805845
    806846    [TestMethod]
    807     [TestCategory("Persistence4")]
     847    [TestCategory("PersistenceNew")]
    808848    [TestProperty("Time", "short")]
    809849    public void TestLongArray() {
     
    822862
    823863    [TestMethod]
    824     [TestCategory("Persistence4")]
     864    [TestCategory("PersistenceNew")]
    825865    [TestProperty("Time", "short")]
    826866    public void TestDoubleArray() {
     
    839879
    840880    [TestMethod]
    841     [TestCategory("Persistence4")]
     881    [TestCategory("PersistenceNew")]
    842882    [TestProperty("Time", "short")]
    843883    public void TestObjectArray() {
     
    863903
    864904    [TestMethod]
    865     [TestCategory("Persistence4")]
     905    [TestCategory("PersistenceNew")]
    866906    [TestProperty("Time", "short")]
    867907    public void TestStack() {
     
    883923
    884924    [TestMethod]
    885     [TestCategory("Persistence4")]
     925    [TestCategory("PersistenceNew")]
    886926    [TestProperty("Time", "short")]
    887927    public void TestArrayOfStack() {
     
    915955
    916956    [TestMethod]
    917     [TestCategory("Persistence4")]
     957    [TestCategory("PersistenceNew")]
    918958    [TestProperty("Time", "short")]
    919959    public void TestIntValueArray() {
     
    932972
    933973    [TestMethod]
    934     [TestCategory("Persistence4")]
     974    [TestCategory("PersistenceNew")]
    935975    [TestProperty("Time", "short")]
    936976    public void TestIntValueArrayArray() {
     
    949989    #endregion
    950990
    951 
    952     #region Old persistence test methods
    953     [TestMethod]
    954     [TestCategory("Persistence4")]
     991    #region Old Persistence Tests
     992    [TestMethod]
     993    [TestCategory("PersistenceNew")]
    955994    [TestProperty("Time", "short")]
    956995    public void ComplexStorable() {
     
    10421081
    10431082    [TestMethod]
    1044     [TestCategory("Persistence4")]
     1083    [TestCategory("PersistenceNew")]
    10451084    [TestProperty("Time", "short")]
    10461085    public void SelfReferences() {
     
    10701109
    10711110    [TestMethod]
    1072     [TestCategory("Persistence4")]
     1111    [TestCategory("PersistenceNew")]
    10731112    [TestProperty("Time", "short")]
    10741113    public void ArrayCreation() {
     
    10831122      arrayListArray[2].Add(arrayListArray);
    10841123      arrayListArray[2].Add(arrayListArray);
    1085       //Array a = Array.CreateInstance(
    1086       //                        typeof(object),
    1087       //                        new[] { 1, 2 }, new[] { 3, 4 });
    1088       //arrayListArray[2].Add(a);
     1124      Array a = Array.CreateInstance(
     1125                              typeof(object),
     1126                              new[] { 1, 2 }, new[] { 3, 4 });
     1127      arrayListArray[2].Add(a);
    10891128      serializer.Serialize(arrayListArray, tempFile);
    10901129      object o = serializer.Deserialize(tempFile);
     
    11001139
    11011140    [TestMethod]
    1102     [TestCategory("Persistence4")]
     1141    [TestCategory("PersistenceNew")]
    11031142    [TestProperty("Time", "short")]
    11041143    public void CustomSerializationProperty() {
     
    11171156
    11181157    [TestMethod]
    1119     [TestCategory("Persistence4")]
     1158    [TestCategory("PersistenceNew")]
    11201159    [TestProperty("Time", "short")]
    11211160    public void Primitives() {
     
    11301169
    11311170    [TestMethod]
    1132     [TestCategory("Persistence4")]
     1171    [TestCategory("PersistenceNew")]
    11331172    [TestProperty("Time", "short")]
    11341173    public void MultiDimensionalArray() {
     
    11611200
    11621201    [TestMethod]
    1163     [TestCategory("Persistence4")]
     1202    [TestCategory("PersistenceNew")]
    11641203    [TestProperty("Time", "short")]
    11651204    public void NestedTypeTest() {
     
    11761215
    11771216    [TestMethod]
    1178     [TestCategory("Persistence4")]
     1217    [TestCategory("PersistenceNew")]
    11791218    [TestProperty("Time", "short")]
    11801219    public void SimpleArray() {
     
    11891228
    11901229    [TestMethod]
    1191     [TestCategory("Persistence4")]
     1230    [TestCategory("PersistenceNew")]
    11921231    [TestProperty("Time", "short")]
    11931232    public void PrimitiveRoot() {
     
    12441283
    12451284    [TestMethod]
    1246     [TestCategory("Persistence4")]
     1285    [TestCategory("PersistenceNew")]
    12471286    [TestProperty("Time", "short")]
    12481287    public void Enums() {
     
    12601299
    12611300    [TestMethod]
    1262     [TestCategory("Persistence4")]
     1301    [TestCategory("PersistenceNew")]
    12631302    [TestProperty("Time", "short")]
    12641303    public void TestAliasingWithOverriddenEquals() {
     
    12781317
    12791318    [TestMethod]
    1280     [TestCategory("Persistence4")]
     1319    [TestCategory("PersistenceNew")]
    12811320    [TestProperty("Time", "short")]
    12821321    public void NonDefaultConstructorTest() {
     
    12911330
    12921331    [TestMethod]
    1293     [TestCategory("Persistence4")]
     1332    [TestCategory("PersistenceNew")]
    12941333    [TestProperty("Time", "short")]
    12951334    public void TestSavingException() {
     
    13081347
    13091348    [TestMethod]
    1310     [TestCategory("Persistence4")]
     1349    [TestCategory("PersistenceNew")]
    13111350    [TestProperty("Time", "short")]
    13121351    public void TestTypeStringConversion() {
     
    13201359
    13211360    [TestMethod]
    1322     [TestCategory("Persistence4")]
     1361    [TestCategory("PersistenceNew")]
    13231362    [TestProperty("Time", "short")]
    13241363    public void TestHexadecimalPublicKeyToken() {
     
    13301369
    13311370    [TestMethod]
    1332     [TestCategory("Persistence4")]
     1371    [TestCategory("PersistenceNew")]
    13331372    [TestProperty("Time", "short")]
    13341373    public void InheritanceTest() {
     
    13601399
    13611400    [TestMethod]
    1362     [TestCategory("Persistence4")]
     1401    [TestCategory("PersistenceNew")]
    13631402    [TestProperty("Time", "short")]
    13641403    public void InstantiateParentChainReference() {
     
    13781417      int value;
    13791418      int PropertyValue { get; set; }
    1380 
    1381       /*
    1382       [StorableConstructor]
    1383       public TestStruct(StorableConstructorFlag deserializing) {
    1384         value = 0;
    1385         PropertyValue = 0;
    1386       }
    1387       */
    1388 
    13891419      public TestStruct(int value)
    13901420        : this() {
     
    13951425
    13961426    [TestMethod]
    1397     [TestCategory("Persistence4")]
     1427    [TestCategory("PersistenceNew")]
    13981428    [TestProperty("Time", "short")]
    13991429    public void StructTest() {
     
    14061436
    14071437    [TestMethod]
    1408     [TestCategory("Persistence4")]
     1438    [TestCategory("PersistenceNew")]
    14091439    [TestProperty("Time", "short")]
    14101440    public void PointTest() {
     
    14171447
    14181448    [TestMethod]
    1419     [TestCategory("Persistence4")]
     1449    [TestCategory("PersistenceNew")]
    14201450    [TestProperty("Time", "short")]
    14211451    public void NullableValueTypes() {
     
    14311461
    14321462    [TestMethod]
    1433     [TestCategory("Persistence4")]
     1463    [TestCategory("PersistenceNew")]
    14341464    [TestProperty("Time", "short")]
    14351465    public void BitmapTest() {
     
    14651495
    14661496    [TestMethod]
    1467     [TestCategory("Persistence4")]
     1497    [TestCategory("PersistenceNew")]
    14681498    [TestProperty("Time", "short")]
    14691499    public void HookTest() {
     
    14911521      }
    14921522      [StorableConstructor]
    1493       private CustomConstructor(StorableConstructorFlag deserializing) {
     1523      private CustomConstructor(StorableConstructorFlag _) {
    14941524        Value = "persistence";
    14951525      }
     
    14971527
    14981528    [TestMethod]
    1499     [TestCategory("Persistence4")]
     1529    [TestCategory("PersistenceNew")]
    15001530    [TestProperty("Time", "short")]
    15011531    public void TestCustomConstructor() {
     
    15181548
    15191549    [TestMethod]
    1520     [TestCategory("Persistence4")]
     1550    [TestCategory("PersistenceNew")]
    15211551    [TestProperty("Time", "short")]
    15221552    public void TestConstructorExceptionUnwrapping() {
     
    15331563
    15341564    [TestMethod]
    1535     [TestCategory("Persistence4")]
     1565    [TestCategory("PersistenceNew")]
    15361566    [TestProperty("Time", "short")]
    15371567    public void TestStreaming() {
     
    15701600
    15711601    [TestMethod]
    1572     [TestCategory("Persistence4")]
     1602    [TestCategory("PersistenceNew")]
    15731603    [TestProperty("Time", "short")]
    15741604    public void TestLinkInheritance() {
     
    15891619      public int Value4 { get; private set; }
    15901620      [StorableConstructor]
    1591       public AllFieldsStorable(StorableConstructorFlag isdeserializing) {
    1592       }
    1593 
    1594       public void InitValues() {
     1621      private AllFieldsStorable(StorableConstructorFlag _) { }
     1622      public AllFieldsStorable() {
    15951623        Value1 = 12;
    15961624        Value2 = 23;
     
    16011629
    16021630    [TestMethod]
    1603     [TestCategory("Persistence4")]
     1631    [TestCategory("PersistenceNew")]
    16041632    [TestProperty("Time", "short")]
    16051633    public void TestStorableTypeDiscoveryAllFields() {
    16061634      ProtoBufSerializer serializer = new ProtoBufSerializer();
    1607       AllFieldsStorable afs = new AllFieldsStorable(default(StorableConstructorFlag));
    1608       afs.InitValues();
     1635      AllFieldsStorable afs = new AllFieldsStorable();
    16091636      serializer.Serialize(afs, tempFile);
    16101637      AllFieldsStorable newAfs = (AllFieldsStorable)serializer.Deserialize(tempFile);
     
    16231650      public int Value4 { get; private set; }
    16241651
     1652      [StorableConstructor]
     1653      private AllPropertiesStorable(StorableConstructorFlag _) { }
    16251654      public AllPropertiesStorable() {
    1626       }
    1627 
    1628       public void InitValues() {
    16291655        Value1 = 12;
    16301656        Value2 = 23;
     
    16351661
    16361662    [TestMethod]
    1637     [TestCategory("Persistence4")]
     1663    [TestCategory("PersistenceNew")]
    16381664    [TestProperty("Time", "short")]
    16391665    public void TestStorableTypeDiscoveryAllProperties() {
    16401666      ProtoBufSerializer serializer = new ProtoBufSerializer();
    16411667      AllPropertiesStorable afs = new AllPropertiesStorable();
    1642       afs.InitValues();
    16431668      serializer.Serialize(afs, tempFile);
    16441669      AllPropertiesStorable newAfs = (AllPropertiesStorable)serializer.Deserialize(tempFile);
     
    16571682      public int Value3 { get; private set; }
    16581683      public int Value4 { get; private set; }
    1659 
     1684      [StorableConstructor]
     1685      private AllFieldsAndAllPropertiesStorable(StorableConstructorFlag _) { }
    16601686      public AllFieldsAndAllPropertiesStorable() {
    1661       }
    1662 
    1663       public void InitValues() {
    16641687        Value1 = 12;
    16651688        Value2 = 23;
    16661689        Value3 = 34;
    16671690        Value4 = 56;
    1668 
    1669       }
    1670     }
    1671 
    1672     [TestMethod]
    1673     [TestCategory("Persistence4")]
     1691      }
     1692    }
     1693
     1694    [TestMethod]
     1695    [TestCategory("PersistenceNew")]
    16741696    [TestProperty("Time", "short")]
    16751697    public void TestStorableTypeDiscoveryAllFieldsAndAllProperties() {
    16761698      ProtoBufSerializer serializer = new ProtoBufSerializer();
    16771699      AllFieldsAndAllPropertiesStorable afs = new AllFieldsAndAllPropertiesStorable();
    1678       afs.InitValues();
    16791700      serializer.Serialize(afs, tempFile);
    16801701      AllFieldsAndAllPropertiesStorable newAfs = (AllFieldsAndAllPropertiesStorable)serializer.Deserialize(tempFile);
     
    16921713      public int Value3 { get; private set; }
    16931714      public int Value4 { get; private set; }
     1715      [StorableConstructor]
     1716      private MarkedOnlyStorable(StorableConstructorFlag _) { }
    16941717      public MarkedOnlyStorable() {
    1695       }
    1696 
    1697       public void InitValues() {
    16981718        Value1 = 12;
    16991719        Value2 = 23;
     
    17041724
    17051725    [TestMethod]
    1706     [TestCategory("Persistence4")]
     1726    [TestCategory("PersistenceNew")]
    17071727    [TestProperty("Time", "short")]
    17081728    public void TestStorableTypeDiscoveryMarkedOnly() {
    17091729      ProtoBufSerializer serializer = new ProtoBufSerializer();
    17101730      MarkedOnlyStorable afs = new MarkedOnlyStorable();
    1711       afs.InitValues();
    17121731      serializer.Serialize(afs, tempFile);
    17131732      MarkedOnlyStorable newAfs = (MarkedOnlyStorable)serializer.Deserialize(tempFile);
     
    17191738
    17201739    [TestMethod]
    1721     [TestCategory("Persistence4")]
     1740    [TestCategory("PersistenceNew")]
    17221741    [TestProperty("Time", "short")]
    17231742    public void TestLineEndings() {
     
    17361755
    17371756    [TestMethod]
    1738     [TestCategory("Persistence4")]
     1757    [TestCategory("PersistenceNew")]
    17391758    [TestProperty("Time", "short")]
    17401759    public void TestSpecialNumbers() {
     
    17521771
    17531772    [TestMethod]
    1754     [TestCategory("Persistence4")]
     1773    [TestCategory("PersistenceNew")]
    17551774    [TestProperty("Time", "short")]
    17561775    public void TestStringSplit() {
     
    17761795
    17771796    [TestMethod]
    1778     [TestCategory("Persistence4")]
     1797    [TestCategory("PersistenceNew")]
    17791798    [TestProperty("Time", "short")]
    17801799    public void TestHashSetSerializer() {
     
    17971816
    17981817    [TestMethod]
    1799     [TestCategory("Persistence4")]
     1818    [TestCategory("PersistenceNew")]
    18001819    [TestProperty("Time", "short")]
    18011820    public void TestConcreteDictionarySerializer() {
     
    18381857
    18391858    [TestMethod]
    1840     [TestCategory("Persistence4")]
     1859    [TestCategory("PersistenceNew")]
    18411860    [TestProperty("Time", "short")]
    18421861    public void TestReadOnlyFail() {
     
    18611880
    18621881    [TestMethod]
    1863     [TestCategory("Persistence4")]
     1882    [TestCategory("PersistenceNew")]
    18641883    [TestProperty("Time", "short")]
    18651884    public void TestWriteOnlyFail() {
     
    18741893    }
    18751894
    1876     [StorableType("8052D9E3-6DDD-4AE1-9B5B-67C6D5436512")]
    1877     public class OneWayTest {
    1878       public OneWayTest() { this.value = "default"; }
    1879       public string value;
    1880       [Storable(AllowOneWay = true)]
    1881       public string ReadOnly {
    1882         get { return "ReadOnly"; }
    1883       }
    1884       [Storable(AllowOneWay = true)]
    1885       public string WriteOnly {
    1886         set { this.value = value; }
    1887       }
    1888     }
    1889 
    1890     //TODO
    1891     /* [TestMethod]
    1892      [TestCategory("Persistence4")]
    1893      [TestProperty("Time", "short")]
    1894      public void TestTypeCacheExport() {
    1895        ProtoBufSerializer serializer = new ProtoBufSerializer();
    1896        var test = new List<List<int>>();
    1897        test.Add(new List<int>() { 1, 2, 3 });
    1898        IEnumerable<Type> types;
    1899        using (var stream = new MemoryStream()) {
    1900          XmlGenerator.Serialize(test, stream, ConfigurationService.Instance.GetConfiguration(new XmlFormat()), false, out types);
    1901        }
    1902        List<Type> t = new List<Type>(types);
    1903        // Assert.IsTrue(t.Contains(typeof(int))); not serialized as an int list is directly transformed into a string
    1904        Assert.IsTrue(t.Contains(typeof(List<int>)));
    1905        Assert.IsTrue(t.Contains(typeof(List<List<int>>)));
    1906        Assert.AreEqual(t.Count, 2);
    1907      }*/
    1908 
    1909     [TestMethod]
    1910     [TestCategory("Persistence4")]
     1895    // TODO
     1896    //[StorableType("8052D9E3-6DDD-4AE1-9B5B-67C6D5436512")]
     1897    //public class OneWayTest {
     1898    //  public OneWayTest() { this.value = "default"; }
     1899    //  public string value;
     1900    //  [Storable(AllowOneWay = true)]
     1901    //  public string ReadOnly {
     1902    //    get { return "ReadOnly"; }
     1903    //  }
     1904    //  [Storable(AllowOneWay = true)]
     1905    //  public string WriteOnly {
     1906    //    set { this.value = value; }
     1907    //  }
     1908    //}
     1909
     1910    //[TestMethod]
     1911    //[TestCategory("PersistenceNew")]
     1912    //[TestProperty("Time", "short")]
     1913    //public void TestTypeCacheExport() {
     1914    //  ProtoBufSerializer serializer = new ProtoBufSerializer();
     1915    //  var test = new List<List<int>>();
     1916    //  test.Add(new List<int>() { 1, 2, 3 });
     1917    //  IEnumerable<Type> types;
     1918    //  using (var stream = new MemoryStream()) {
     1919    //    XmlGenerator.Serialize(test, stream, ConfigurationService.Instance.GetConfiguration(new XmlFormat()), false, out types);
     1920    //  }
     1921    //  List<Type> t = new List<Type>(types);
     1922    //  // Assert.IsTrue(t.Contains(typeof(int))); not serialized as an int list is directly transformed into a string
     1923    //  Assert.IsTrue(t.Contains(typeof(List<int>)));
     1924    //  Assert.IsTrue(t.Contains(typeof(List<List<int>>)));
     1925    //  Assert.AreEqual(t.Count, 2);
     1926    //}
     1927
     1928    [TestMethod]
     1929    [TestCategory("PersistenceNew")]
    19111930    [TestProperty("Time", "short")]
    19121931    public void TupleTest() {
     
    19221941
    19231942    [TestMethod]
    1924     [TestCategory("Persistence4")]
     1943    [TestCategory("PersistenceNew")]
    19251944    [TestProperty("Time", "short")]
    19261945    public void FontTest() {
     
    19411960
    19421961    [TestMethod]
    1943     [TestCategory("Persistence4")]
     1962    [TestCategory("PersistenceNew")]
    19441963    [TestProperty("Time", "medium")]
    19451964    public void ConcurrencyTest() {
     
    19601979
    19611980    [TestMethod]
    1962     [TestCategory("Persistence4")]
     1981    [TestCategory("PersistenceNew")]
    19631982    [TestProperty("Time", "medium")]
    19641983    public void ConcurrentBitmapTest() {
     
    19922011    }
    19932012
    1994 
    1995     [TestMethod]
    1996     [TestCategory("Persistence4")]
     2013    [TestMethod]
     2014    [TestCategory("PersistenceNew")]
    19972015    [TestProperty("Time", "short")]
    19982016    public void TestSpecialCharacters() {
     
    20052023
    20062024    [TestMethod]
    2007     [TestCategory("Persistence4")]
     2025    [TestCategory("PersistenceNew")]
    20082026    [TestProperty("Time", "short")]
    20092027    public void TestByteArray() {
     
    20192037
    20202038    [TestMethod]
    2021     [TestCategory("Persistence4")]
     2039    [TestCategory("PersistenceNew")]
    20222040    [TestProperty("Time", "short")]
    20232041    public void TestOptionalNumberEnumerable() {
     
    20302048
    20312049    [TestMethod]
    2032     [TestCategory("Persistence4")]
     2050    [TestCategory("PersistenceNew")]
    20332051    [TestProperty("Time", "short")]
    20342052    public void TestOptionalDateTimeEnumerable() {
     
    20422060
    20432061    [TestMethod]
    2044     [TestCategory("Persistence4")]
     2062    [TestCategory("PersistenceNew")]
    20452063    [TestProperty("Time", "short")]
    20462064    public void TestStringEnumerable() {
     
    20532071
    20542072    [TestMethod]
    2055     [TestCategory("Persistence4")]
     2073    [TestCategory("PersistenceNew")]
    20562074    [TestProperty("Time", "short")]
    20572075    public void TestUnicodeCharArray() {
     
    20642082
    20652083    [TestMethod]
    2066     [TestCategory("Persistence4")]
     2084    [TestCategory("PersistenceNew")]
    20672085    [TestProperty("Time", "short")]
    20682086    public void TestUnicode() {
     
    20752093
    20762094    [TestMethod]
    2077     [TestCategory("Persistence4")]
     2095    [TestCategory("PersistenceNew")]
    20782096    [TestProperty("Time", "short")]
    20792097    public void TestQueue() {
     
    20862104    #endregion
    20872105
     2106    #region New Persistence Tests
    20882107    [StorableType("6075F1E8-948A-4AD8-8F5A-942B777852EC")]
    20892108    public class A {
     
    21062125
    21072126    [TestMethod]
    2108     [TestCategory("Persistence4")]
     2127    [TestCategory("PersistenceNew")]
    21092128    [TestProperty("Time", "short")]
    21102129    public void TestCyclicReferencesWithTuple() {
     
    22482267
    22492268    [TestMethod]
    2250     [TestCategory("Persistence4")]
     2269    [TestCategory("PersistenceNew")]
    22512270    [TestProperty("Time", "short")]
    22522271    public void TestConversion() {
     
    22662285      var old = test();
    22672286      serializer.Serialize(old, tempFile);
    2268       Mapper.StaticCache.DeregisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(V1)).Guid);
    2269       Mapper.StaticCache.DeregisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(V2)).Guid);
    2270       Mapper.StaticCache.DeregisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(V3)).Guid);
    2271       Mapper.StaticCache.RegisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(V1)).Guid, typeof(V3));
    2272 
    2273       var typeInfosField = typeof(StaticCache).GetField("typeInfos", BindingFlags.NonPublic | BindingFlags.Instance);
    2274       var typeInfos = (Dictionary<Type, Persistence.TypeInfo>)typeInfosField.GetValue(Mapper.StaticCache);
    2275 
    2276       var guidPI = typeof(StorableTypeAttribute).GetProperty("Guid");
    2277       var convPI = typeof(Persistence.TypeInfo).GetProperty("ConversionMethods");
    2278 
    2279       var oldBInfo = typeInfos[typeof(V1)];
    2280       var newBInfo = Mapper.StaticCache.GetTypeInfo(typeof(V3));
    2281       guidPI.SetValue(newBInfo.StorableTypeAttribute, oldBInfo.StorableTypeAttribute.Guid);
    2282       //convPI.SetValue(newBInfo, oldBInfo.ConversionMethods);
    2283       typeInfos.Remove(typeof(V1));
     2287
     2288      DeregisterType(typeof(V1));
     2289      DeregisterType(typeof(V2));
     2290      DeregisterType(typeof(V3));
     2291
     2292      RegisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(V1)).Guid, typeof(V3));
     2293      SetTypeGuid(typeof(V3), GetTypeGuid(typeof(V1)));
     2294      RemoveTypeInfo(typeof(V1));
    22842295
    22852296      object o = serializer.Deserialize(tempFile);
     
    22912302      Assert.AreSame(restored, restored.mySelf);
    22922303      Assert.AreEqual(restored.PublicString, old.s);
    2293       //string msg = Profile(test);
    2294       //Console.WriteLine(msg);
    22952304    }
    22962305
     
    22982307
    22992308    [TestMethod]
    2300     [TestCategory("Persistence4")]
     2309    [TestCategory("PersistenceNew")]
    23012310    [TestProperty("Time", "short")]
    23022311    public void TestGASerializeDeserializeExecute() {
     
    23262335
    23272336    [TestMethod]
    2328     [TestCategory("Persistence4")]
     2337    [TestCategory("PersistenceNew")]
    23292338    [TestProperty("Time", "short")]
    23302339    public void TestLoadingSamples() {
     
    24132422
    24142423    [TestMethod]
    2415     [TestCategory("Persistence4")]
     2424    [TestCategory("PersistenceNew")]
    24162425    [TestProperty("Time", "short")]
    24172426    public void TestConversionCase1() {
     
    24232432      var old = test();
    24242433      serializer.Serialize(old, tempFile);
    2425       Mapper.StaticCache.DeregisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(ConversionB)).Guid);
    2426       Mapper.StaticCache.DeregisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(ConversionBNew)).Guid);
    2427       Mapper.StaticCache.DeregisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(ConversionA)).Guid);
    2428       Mapper.StaticCache.DeregisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(ConversionANew)).Guid);
    2429       Mapper.StaticCache.RegisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(ConversionB)).Guid, typeof(ConversionBNew));
    2430       Mapper.StaticCache.RegisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(ConversionA)).Guid, typeof(ConversionANew));
    2431 
    2432       var typeInfosField = typeof(StaticCache).GetField("typeInfos", BindingFlags.NonPublic | BindingFlags.Instance);
    2433       var typeInfos = (Dictionary<Type, Persistence.TypeInfo>)typeInfosField.GetValue(Mapper.StaticCache);
    2434 
    2435       var guidPI = typeof(StorableTypeAttribute).GetProperty("Guid");
    2436       var convPI = typeof(Persistence.TypeInfo).GetProperty("ConversionMethods");
    2437 
    2438       var oldAInfo = typeInfos[typeof(ConversionA)];
    2439       var newAInfo = Mapper.StaticCache.GetTypeInfo(typeof(ConversionANew));
    2440       guidPI.SetValue(newAInfo.StorableTypeAttribute, oldAInfo.StorableTypeAttribute.Guid);
    2441       //convPI.SetValue(newAInfo, oldAInfo.ConversionMethods);
    2442       typeInfos.Remove(typeof(ConversionA));
    2443 
    2444       var oldBInfo = typeInfos[typeof(ConversionB)];
    2445       var newBInfo = Mapper.StaticCache.GetTypeInfo(typeof(ConversionBNew));
    2446       guidPI.SetValue(newBInfo.StorableTypeAttribute, oldBInfo.StorableTypeAttribute.Guid);
    2447       //convPI.SetValue(newBInfo, oldBInfo.ConversionMethods);
    2448       typeInfos.Remove(typeof(ConversionB));
     2434
     2435      DeregisterType(typeof(ConversionB));
     2436      DeregisterType(typeof(ConversionBNew));
     2437      DeregisterType(typeof(ConversionA));
     2438      DeregisterType(typeof(ConversionANew));
     2439
     2440      RegisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(ConversionA)).Guid, typeof(ConversionANew));
     2441      SetTypeGuid(typeof(ConversionANew), GetTypeGuid(typeof(ConversionA)));
     2442      RemoveTypeInfo(typeof(ConversionA));
     2443
     2444      RegisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(ConversionB)).Guid, typeof(ConversionBNew));
     2445      SetTypeGuid(typeof(ConversionBNew), GetTypeGuid(typeof(ConversionB)));
     2446      RemoveTypeInfo(typeof(ConversionB));
    24492447
    24502448      object o = serializer.Deserialize(tempFile);
     
    24532451      Assert.AreEqual(restored.BaseG, old.BaseF);
    24542452    }
     2453
     2454    [StorableType("90470973-4559-428E-AF28-DD95866B0A84")]
     2455    private class A0 {
     2456      [Storable]
     2457      public int x;
     2458    }
     2459
     2460    [StorableType("00000000-0000-0000-0000-0000000000A1", 2)]
     2461    private class A1 {
     2462      [Storable]
     2463      public int y;
     2464    }
     2465
     2466    [StorableType("847DD840-3EE3-4A01-AC60-FD7E71ED05F8")]
     2467    private class B0 {
     2468      [Storable]
     2469      public int x;
     2470    }
     2471
     2472    [StorableType("00000000-0000-0000-0000-0000000000B1", 2)]
     2473    private class B1 : A0 { }
     2474
     2475    [StorableType("00000000-0000-0000-0000-0000000000B2", 3)]
     2476    private class B2 {
     2477      [Storable]
     2478      public int x;
     2479    }
     2480
     2481    private static class ConversionsA2A_B2B {
     2482      [StorableConversion("847DD840-3EE3-4A01-AC60-FD7E71ED05F8", 1, baseGuid: "90470973-4559-428E-AF28-DD95866B0A84", baseVersion: 1)]
     2483      private static Dictionary<string, object> ConvertB0_B1(Dictionary<string, object> values) {
     2484        var newValues = new Dictionary<string, object>();
     2485        newValues["90470973-4559-428E-AF28-DD95866B0A84.x"] = values["847DD840-3EE3-4A01-AC60-FD7E71ED05F8.x"];
     2486        return newValues;
     2487      }
     2488
     2489      [StorableConversion("90470973-4559-428E-AF28-DD95866B0A84", 1)]
     2490      private static Dictionary<string, object> ConvertA0_A1(Dictionary<string, object> values) {
     2491        var newValues = new Dictionary<string, object>();
     2492        newValues["90470973-4559-428E-AF28-DD95866B0A84.y"] = values["90470973-4559-428E-AF28-DD95866B0A84.x"];
     2493        return newValues;
     2494      }
     2495
     2496      [StorableConversion("847DD840-3EE3-4A01-AC60-FD7E71ED05F8", 2)]
     2497      private static Dictionary<string, object> ConvertB1_B2(Dictionary<string, object> values) {
     2498        var newValues = new Dictionary<string, object>();
     2499        newValues["847DD840-3EE3-4A01-AC60-FD7E71ED05F8.x"] = values["90470973-4559-428E-AF28-DD95866B0A84.y"];
     2500        return newValues;
     2501      }
     2502    }
     2503
     2504    [TestMethod]
     2505    [TestCategory("PersistenceNew")]
     2506    [TestProperty("Time", "short")]
     2507    public void TestConversionCase2() {
     2508      var test = new Func<B0>(() => {
     2509        return new B0() { x = 17 };
     2510      });
     2511
     2512      ProtoBufSerializer serializer = new ProtoBufSerializer();
     2513      var old = test();
     2514      serializer.Serialize(old, tempFile);
     2515
     2516      DeregisterType(typeof(B0));
     2517      DeregisterType(typeof(B1));
     2518      DeregisterType(typeof(B2));
     2519      DeregisterType(typeof(A0));
     2520      DeregisterType(typeof(A1));
     2521
     2522      RegisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(B0)).Guid, typeof(B2));
     2523      SetTypeGuid(typeof(B2), GetTypeGuid(typeof(B0)));
     2524      RemoveTypeInfo(typeof(B0));
     2525
     2526      RegisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(A0)).Guid, typeof(A1));
     2527      SetTypeGuid(typeof(A1), GetTypeGuid(typeof(A0)));
     2528      RemoveTypeInfo(typeof(A0));
     2529
     2530      object o = serializer.Deserialize(tempFile);
     2531      var restored = (B2)o;
     2532      Assert.AreEqual(restored.x, old.x);
     2533    }
     2534
     2535    #region Inheritance Chain Test
     2536    [StorableType("C1BFC249-89F6-45E2-8DFB-DA95E1BE9B95")]
     2537    private class InheritanceA0 {
     2538      [Storable]
     2539      public int x;
     2540    }
     2541
     2542    [StorableType("00000000-0000-0000-0000-0000000001A1", 2)]
     2543    private class InheritanceA1 {
     2544      [Storable]
     2545      public int y;
     2546    }
     2547
     2548    [StorableType("28A5F6B8-49AF-4C6A-AF0E-F92EB4511722", 1)]
     2549    private class InheritanceC0 {
     2550      [Storable]
     2551      public int x;
     2552    }
     2553
     2554    [StorableType("00000000-0000-0000-0000-0000000001C1", 2)]
     2555    private class InheritanceC1 {
     2556      [Storable]
     2557      public int x;
     2558    }
     2559
     2560    [StorableType("41108958-227D-43C4-B049-80AD0D3DB7F6")]
     2561    private class InheritanceB0 : InheritanceA0 {
     2562      //[Storable]
     2563      //public int x;
     2564    }
     2565
     2566    [StorableType("00000000-0000-0000-0000-0000000001B1", 2)]
     2567    private class InheritanceB1 : InheritanceC1 { }
     2568
     2569    private static class InheritanceConversionsA2A_B2B {
     2570      [StorableConversion("C1BFC249-89F6-45E2-8DFB-DA95E1BE9B95", 1)]
     2571      private static Dictionary<string, object> ConvertA0_A1(Dictionary<string, object> values) {
     2572        var newValues = new Dictionary<string, object>();
     2573        newValues["C1BFC249-89F6-45E2-8DFB-DA95E1BE9B95.y"] = values["C1BFC249-89F6-45E2-8DFB-DA95E1BE9B95.x"];
     2574        return newValues;
     2575      }
     2576
     2577      [StorableConversion("41108958-227D-43C4-B049-80AD0D3DB7F6", 1, baseGuid: "C1BFC249-89F6-45E2-8DFB-DA95E1BE9B95", baseVersion: 2)]
     2578      private static Dictionary<string, object> ConvertB0_B1(Dictionary<string, object> values, out List<Tuple<string, uint>> typeChain) {
     2579        typeChain = new List<Tuple<string, uint>> {
     2580          Tuple.Create("28A5F6B8-49AF-4C6A-AF0E-F92EB4511722", 1u)
     2581        };
     2582
     2583        var newValues = new Dictionary<string, object>();
     2584        newValues["41108958-227D-43C4-B049-80AD0D3DB7F6.x"] = values["C1BFC249-89F6-45E2-8DFB-DA95E1BE9B95.y"];
     2585        newValues["28A5F6B8-49AF-4C6A-AF0E-F92EB4511722.x"] = values["C1BFC249-89F6-45E2-8DFB-DA95E1BE9B95.y"];
     2586        return newValues;
     2587      }
     2588
     2589      [StorableConversion("28A5F6B8-49AF-4C6A-AF0E-F92EB4511722", 1)]
     2590      private static Dictionary<string, object> ConvertC0_C1(Dictionary<string, object> values) {
     2591        var newValues = new Dictionary<string, object>();
     2592        newValues["41108958-227D-43C4-B049-80AD0D3DB7F6.x"] = (int)values["41108958-227D-43C4-B049-80AD0D3DB7F6.x"] * 2;
     2593        return newValues;
     2594      }
     2595    }
     2596
     2597    [TestMethod]
     2598    [TestCategory("PersistenceNew")]
     2599    [TestProperty("Time", "short")]
     2600    public void TestInheritanceConversionCase1() {
     2601      var test = new Func<InheritanceB0>(() => {
     2602        return new InheritanceB0() { x = 17 };
     2603      });
     2604
     2605      ProtoBufSerializer serializer = new ProtoBufSerializer();
     2606      var old = test();
     2607      serializer.Serialize(old, tempFile);
     2608
     2609      DeregisterType(typeof(InheritanceB0));
     2610      DeregisterType(typeof(InheritanceB1));
     2611      DeregisterType(typeof(InheritanceA0));
     2612      DeregisterType(typeof(InheritanceA1));
     2613      DeregisterType(typeof(InheritanceC0));
     2614      DeregisterType(typeof(InheritanceC1));
     2615
     2616      RegisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(InheritanceA0)).Guid, typeof(InheritanceA1));
     2617      SetTypeGuid(typeof(InheritanceA1), GetTypeGuid(typeof(InheritanceA0)));
     2618      RemoveTypeInfo(typeof(InheritanceA0));
     2619
     2620      RegisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(InheritanceB0)).Guid, typeof(InheritanceB1));
     2621      SetTypeGuid(typeof(InheritanceB1), GetTypeGuid(typeof(InheritanceB0)));
     2622      RemoveTypeInfo(typeof(InheritanceB0));
     2623
     2624      RegisterType(StorableTypeAttribute.GetStorableTypeAttribute(typeof(InheritanceC0)).Guid, typeof(InheritanceC1));
     2625      SetTypeGuid(typeof(InheritanceC1), GetTypeGuid(typeof(InheritanceC0)));
     2626      RemoveTypeInfo(typeof(InheritanceC0));
     2627
     2628      object o = serializer.Deserialize(tempFile);
     2629      var restoredC1 = (InheritanceC1)o;
     2630      var restoredB1 = (InheritanceB1)o;
     2631      Assert.AreEqual(old.x, restoredB1.x);
     2632      Assert.AreEqual(old.x * 2, restoredC1.x);
     2633    }
     2634    #endregion
     2635    #endregion
    24552636  }
    24562637}
Note: See TracChangeset for help on using the changeset viewer.