- Timestamp:
- 03/20/17 15:56:55 (8 years ago)
- Location:
- branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Transformers
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Transformers/StorableClassTransformer.cs
r14713 r14771 70 70 var type = obj.GetType(); 71 71 var typeInfo = Mapper.StaticCache.GetTypeInfo(type); 72 var typeBox = mapper.GetBox(box.TypeId).GetExtension(TypeBox.Type); 73 var version = typeBox.HasVersion ? typeBox.Version : 1; 72 74 73 75 var components = new Dictionary<uint, uint>(); … … 76 78 } 77 79 80 var conversionMethods = 81 type.GetMethods(BindingFlags.NonPublic | BindingFlags.Static) 82 .Where(StorableConversionAttribute.IsStorableConversionMethod) 83 .Where(mi => StorableConversionAttribute.GetVersion(mi) >= version) 84 .OrderBy(StorableConversionAttribute.GetVersion); 85 86 // put all objects into dictionary for optional conversion 87 var dict = new Dictionary<string, object>(); 88 foreach (var component in components) { 89 dict.Add(mapper.GetString(component.Key), mapper.GetObject(component.Value)); 90 } 91 92 // TODO: check that all entries in the dictionary can be mapped to a field or property 93 foreach (var convMeth in conversionMethods) { 94 dict = (Dictionary<string, object>)convMeth.Invoke(null, new object[] { dict }); 95 } 96 78 97 foreach (var componentInfo in typeInfo.Fields) { 79 98 var field = (FieldInfo)componentInfo.MemberInfo; 80 uint componentId;81 bool found = components.TryGetValue(mapper.GetStringId(componentInfo.Name), out componentId);99 object val = null; 100 bool found = dict.TryGetValue(componentInfo.Name, out val); 82 101 if (found) 83 field.SetValue(obj, mapper.GetObject(componentId));102 field.SetValue(obj, val); 84 103 else if (componentInfo.StorableAttribute.DefaultValue != null) 85 104 field.SetValue(obj, componentInfo.StorableAttribute.DefaultValue); … … 88 107 foreach (var componentInfo in typeInfo.Properties.Where(x => x.Writeable)) { 89 108 var property = (PropertyInfo)componentInfo.MemberInfo; 90 uint componentId;91 bool found = components.TryGetValue(mapper.GetStringId(componentInfo.Name), out componentId);109 object val = null; 110 bool found = dict.TryGetValue(componentInfo.Name, out val); 92 111 if (found) 93 property.SetValue(obj, mapper.GetObject(componentId), null);112 property.SetValue(obj, val, null); 94 113 else if (componentInfo.StorableAttribute.DefaultValue != null) 95 114 property.SetValue(obj, componentInfo.StorableAttribute.DefaultValue, null); -
branches/PersistenceOverhaul/HeuristicLab.Persistence/4.0/Transformers/Transformers.cs
r14711 r14771 299 299 box.TypeId = mapper.GetTypeId(type); 300 300 } 301 302 if (StorableTypeAttribute.IsStorableType(type)) 303 typeBox.Version = StorableTypeAttribute.GetStorableTypeAttribute(type).Version; 301 304 box.SetExtension(TypeBox.Type, typeBox.Build()); 302 305 }
Note: See TracChangeset
for help on using the changeset viewer.