- Timestamp:
- 05/15/09 12:29:13 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Persistence/3.3/Core/DeSerializer.cs
r1795 r1823 8 8 9 9 namespace HeuristicLab.Persistence.Core { 10 11 public class TypeLoader {12 13 public static Type Load(string typeNameString) {14 Type type;15 try {16 type = Type.GetType(typeNameString, true);17 } catch (Exception) {18 Logger.Warn(String.Format(19 "Cannot load type \"{0}\", falling back to partial name", typeNameString));20 try {21 TypeName typeName = TypeNameParser.Parse(typeNameString);22 Assembly a = Assembly.LoadWithPartialName(typeName.AssemblyName);23 type = a.GetType(typeName.ToString(false, false), true);24 } catch (Exception) {25 throw new PersistenceException(String.Format(26 "Could not load type \"{0}\"",27 typeNameString));28 }29 try {30 TypeName requestedTypeName = TypeNameParser.Parse(typeNameString);31 TypeName loadedTypeName = TypeNameParser.Parse(type.AssemblyQualifiedName);32 if (!requestedTypeName.IsCompatible(loadedTypeName))33 throw new PersistenceException(String.Format(34 "Serialized type is incompatible with available type: serialized: {0}, loaded: {1}",35 typeNameString,36 type.AssemblyQualifiedName));37 if (requestedTypeName.IsNewerThan(loadedTypeName))38 throw new PersistenceException(String.Format(39 "Serialized type is newer than available type: serialized: {0}, loaded: {1}",40 typeNameString,41 type.AssemblyQualifiedName));42 } catch (PersistenceException) {43 throw;44 } catch (Exception e) {45 Logger.Warn(String.Format(46 "Could not perform version check requested type was {0} while loaded type is {1}:",47 typeNameString,48 type.AssemblyQualifiedName),49 e);50 }51 }52 return type;53 }54 55 }56 10 57 11 public class Deserializer { … … 66 20 private List<Tag> customValues; 67 21 private Type type; 68 private I Decomposer decomposer;22 private ICompositeSerializer compositeSerializer; 69 23 70 24 public Midwife(object value) { … … 72 26 } 73 27 74 public Midwife(Type type, I Decomposer decomposer, int? id) {28 public Midwife(Type type, ICompositeSerializer compositeSerializer, int? id) { 75 29 this.type = type; 76 this. decomposer = decomposer;30 this.compositeSerializer = compositeSerializer; 77 31 this.Id = id; 78 32 MetaMode = false; … … 84 38 if (Obj != null) 85 39 throw new PersistenceException("object already instantiated"); 86 Obj = decomposer.CreateInstance(type, metaInfo);40 Obj = compositeSerializer.CreateInstance(type, metaInfo); 87 41 } 88 42 … … 96 50 97 51 public void Populate() { 98 decomposer.Populate(Obj, customValues, type);52 compositeSerializer.Populate(Obj, customValues, type); 99 53 } 100 54 } … … 159 113 private void CompositeStartHandler(BeginToken token) { 160 114 Type type = typeIds[(int)token.TypeId]; 161 I Decomposer decomposer = null;115 ICompositeSerializer compositeSerializer = null; 162 116 if (serializerMapping.ContainsKey(type)) 163 decomposer = serializerMapping[type] as IDecomposer;164 if ( decomposer == null)117 compositeSerializer = serializerMapping[type] as ICompositeSerializer; 118 if (compositeSerializer == null) 165 119 throw new PersistenceException(String.Format( 166 120 "No suitable method for deserialization of type \"{0}\" found.", 167 121 type.VersionInvariantName())); 168 parentStack.Push(new Midwife(type, decomposer, token.Id));122 parentStack.Push(new Midwife(type, compositeSerializer, token.Id)); 169 123 } 170 124 … … 180 134 private void PrimitiveHandler(PrimitiveToken token) { 181 135 Type type = typeIds[(int)token.TypeId]; 182 object value = ((I Formatter)serializerMapping[type]).Parse(token.SerialData);136 object value = ((IPrimitiveSerializer)serializerMapping[type]).Parse(token.SerialData); 183 137 if (token.Id != null) 184 138 id2obj[(int)token.Id] = value;
Note: See TracChangeset
for help on using the changeset viewer.