Changeset 1780 for trunk/sources/HeuristicLab.Persistence/3.3/Core
- Timestamp:
- 05/11/09 16:09:29 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Persistence/3.3/Core
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Persistence/3.3/Core/DeSerializer.cs
r1779 r1780 9 9 namespace HeuristicLab.Persistence.Core { 10 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 loading with 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 if ( 31 TypeNameParser.Parse(type.AssemblyQualifiedName).IsOlderThan( 32 TypeNameParser.Parse(typeNameString))) 33 throw new PersistenceException(String.Format( 34 "Serialized type is newer than available type: serialized: {0}, loaded: {1}", 35 typeNameString, 36 type.AssemblyQualifiedName)); 37 } catch (PersistenceException) { 38 throw; 39 } catch (Exception e) { 40 Logger.Warn(String.Format( 41 "Could not perform version check requested type was {0} while loaded type is {1}:", 42 typeNameString, 43 type.AssemblyQualifiedName), 44 e); 45 } 46 } 47 return type; 48 } 49 50 } 51 11 52 public class Deserializer { 12 53 … … 71 112 var map = new Dictionary<Type, object>(); 72 113 foreach (var typeMapping in typeCache) { 73 Type type; 74 try { 75 type = Type.GetType(typeMapping.TypeName, true); 76 } catch (Exception) { 77 Logger.Error(String.Format( 78 "Cannot load type \"{0}\", falling back to loading with partial name", typeMapping.TypeName)); 79 string[] typeNameParts = typeMapping.TypeName.Split(new[] { ',' }); 80 try { 81 Assembly a = Assembly.LoadWithPartialName(typeNameParts[typeNameParts.Length - 1].Trim()); 82 Array.Resize(ref typeNameParts, typeNameParts.Length - 1); 83 type = a.GetType(string.Join(",", typeNameParts), true); 84 } catch (Exception) { 85 throw new PersistenceException(String.Format( 86 "Could not load type \"{0}\"", 87 typeMapping.TypeName)); 88 } 89 } 114 Type type = TypeLoader.Load(typeMapping.TypeName); 90 115 typeIds.Add(typeMapping.Id, type); 91 Type serializerType = Type .GetType(typeMapping.Serializer, true);116 Type serializerType = TypeLoader.Load(typeMapping.Serializer); 92 117 map.Add(type, Activator.CreateInstance(serializerType, true)); 93 118 } … … 101 126 } 102 127 } 128 103 129 104 130 public object Deserialize(IEnumerable<ISerializationToken> tokens) { -
trunk/sources/HeuristicLab.Persistence/3.3/Core/Serializer.cs
r1710 r1780 40 40 IFormatter f = configuration.GetFormatter(pair.Key); 41 41 if (f != null) { 42 serializer = f.GetType(). VersionInvariantName();42 serializer = f.GetType().AssemblyQualifiedName; 43 43 } else { 44 44 IDecomposer d = configuration.GetDecomposer(pair.Key); 45 serializer = d.GetType(). VersionInvariantName();45 serializer = d.GetType().AssemblyQualifiedName; 46 46 } 47 //result.Add(new TypeMapping(pair.Value, pair.Key.AssemblyQualifiedName, serializer)); 47 48 result.Add(new TypeMapping(pair.Value, pair.Key.VersionInvariantName(), serializer)); 48 49 }
Note: See TracChangeset
for help on using the changeset viewer.