Changeset 16210 for branches/PersistenceReintegration/HeuristicLab.Persistence/4.0/Transformers/Transformers.cs
- Timestamp:
- 10/03/18 17:48:20 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PersistenceReintegration/HeuristicLab.Persistence/4.0/Transformers/Transformers.cs
r15986 r16210 473 473 [Transformer("C47A62F5-F113-4A43-A8EE-CF817EC799A2", 303)] 474 474 [StorableType("BA53DF84-DC97-4D8D-A493-868972ED1002")] 475 internal sealed class DictionaryTransformer: BoxTransformer<object> {475 internal sealed class IDictionary : BoxTransformer<object> { 476 476 public override bool CanTransformType(Type type) { 477 477 return type.IsGenericType && typeof(Dictionary<,>) == type.GetGenericTypeDefinition(); … … 480 480 protected override void Populate(Box box, object value, Mapper mapper) { 481 481 var kvps = box.KeyValuePairs; 482 foreach (DictionaryEntry item in ( IDictionary)value)482 foreach (DictionaryEntry item in (System.Collections.IDictionary)value) 483 483 kvps.Add(mapper.GetBoxId(item.Key), mapper.GetBoxId(item.Value)); 484 484 … … 855 855 if (attrib != null && attrib.DefaultValue != null) 856 856 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); 857 863 } 864 858 865 foreach (var componentInfo in typeInfo.Properties.Where(x => x.Writeable)) { 859 866 var attrib = componentInfo.StorableAttribute; … … 861 868 if (attrib != null && attrib.DefaultValue != null) 862 869 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); 863 876 } 864 877 865 878 // 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 check881 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 check889 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 //} 892 905 893 906 //var undefinedMembers = dict.Where(x => Guid.Parse(x.Key.Split('.')[0]) == typeInfo.StorableTypeAttribute.Guid);
Note: See TracChangeset
for help on using the changeset viewer.