Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/03/18 17:48:20 (6 years ago)
Author:
jkarder
Message:

#2520: worked on new persistence

  • added cache for different attributes
  • refactored StorableTypeBoxTransformer
  • implemented paths for Storable members
  • implemented more unit tests
File:
1 edited

Legend:

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

    r15986 r16210  
    473473  [Transformer("C47A62F5-F113-4A43-A8EE-CF817EC799A2", 303)]
    474474  [StorableType("BA53DF84-DC97-4D8D-A493-868972ED1002")]
    475   internal sealed class DictionaryTransformer : BoxTransformer<object> {
     475  internal sealed class IDictionary : BoxTransformer<object> {
    476476    public override bool CanTransformType(Type type) {
    477477      return type.IsGenericType && typeof(Dictionary<,>) == type.GetGenericTypeDefinition();
     
    480480    protected override void Populate(Box box, object value, Mapper mapper) {
    481481      var kvps = box.KeyValuePairs;
    482       foreach (DictionaryEntry item in (IDictionary)value)
     482      foreach (DictionaryEntry item in (System.Collections.IDictionary)value)
    483483        kvps.Add(mapper.GetBoxId(item.Key), mapper.GetBoxId(item.Value));
    484484
     
    855855          if (attrib != null && attrib.DefaultValue != null)
    856856            fieldInfo.SetValue(obj, attrib.DefaultValue);
     857
     858          object value;
     859          if (!dict.TryGetValue(componentInfo.FullName, out value)) continue;
     860
     861          var field = (FieldInfo)componentInfo.MemberInfo;
     862          field.SetValue(obj, value);
    857863        }
     864
    858865        foreach (var componentInfo in typeInfo.Properties.Where(x => x.Writeable)) {
    859866          var attrib = componentInfo.StorableAttribute;
     
    861868          if (attrib != null && attrib.DefaultValue != null)
    862869            property.SetValue(obj, attrib.DefaultValue, null);
     870
     871          object value;
     872          if (!dict.TryGetValue(componentInfo.FullName, out value)) continue;
     873
     874          var prop = (PropertyInfo)componentInfo.MemberInfo;
     875          prop.SetValue(obj, value, null);
    863876        }
    864877
    865878        // set all members
    866         foreach (var kvp in dict) {
    867           string key = kvp.Key;
    868           object val = kvp.Value;
    869 
    870           string[] keyParts = key.Split('.');
    871           var guid = Guid.Parse(keyParts[0]);
    872           string ident = keyParts[1];
    873 
    874           if (guid != typeInfo.StorableTypeAttribute.Guid) continue;
    875 
    876           var fieldInfo = typeInfo.Fields.FirstOrDefault(fi => fi.Name == ident);
    877           if (fieldInfo != null) {
    878             var field = (FieldInfo)fieldInfo.MemberInfo;
    879             field.SetValue(obj, val);
    880             //dict.Remove(guid.ToString().ToUpperInvariant() + "." + fieldInfo.Name); // only for consistency check
    881             continue;
    882           }
    883 
    884           var propInfo = typeInfo.Properties.Where(x => x.Writeable).FirstOrDefault(fi => fi.Name == ident);
    885           if (propInfo != null) {
    886             var prop = (PropertyInfo)propInfo.MemberInfo;
    887             prop.SetValue(obj, val, null);
    888             //dict.Remove(guid.ToString().ToUpperInvariant() + "." + propInfo.Name); // only for consistency check
    889             continue;
    890           }
    891         }
     879        //foreach (var kvp in dict) {
     880        //  string key = kvp.Key;
     881        //  object val = kvp.Value;
     882
     883        //  string[] keyParts = key.Split('.');
     884        //  var guid = Guid.Parse(keyParts[0]);
     885        //  string ident = keyParts[1];
     886
     887        //  if (guid != typeInfo.StorableTypeAttribute.Guid) continue;
     888
     889        //  var fieldInfo = typeInfo.Fields.FirstOrDefault(fi => fi.Name == ident);
     890        //  if (fieldInfo != null) {
     891        //    var field = (FieldInfo)fieldInfo.MemberInfo;
     892        //    field.SetValue(obj, val);
     893        //    //dict.Remove(guid.ToString().ToUpperInvariant() + "." + fieldInfo.Name); // only for consistency check
     894        //    continue;
     895        //  }
     896
     897        //  var propInfo = typeInfo.Properties.Where(x => x.Writeable).FirstOrDefault(fi => fi.Name == ident);
     898        //  if (propInfo != null) {
     899        //    var prop = (PropertyInfo)propInfo.MemberInfo;
     900        //    prop.SetValue(obj, val, null);
     901        //    //dict.Remove(guid.ToString().ToUpperInvariant() + "." + propInfo.Name); // only for consistency check
     902        //    continue;
     903        //  }
     904        //}
    892905
    893906        //var undefinedMembers = dict.Where(x => Guid.Parse(x.Key.Split('.')[0]) == typeInfo.StorableTypeAttribute.Guid);
Note: See TracChangeset for help on using the changeset viewer.