Changeset 1859 for trunk/sources/HeuristicLab.Persistence
- Timestamp:
- 05/20/09 11:42:53 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Persistence/3.3/Core/DeSerializer.cs
r1823 r1859 68 68 69 69 private Dictionary<Type, object> CreateSerializers(IEnumerable<TypeMapping> typeCache) { 70 Dictionary<Type, object> serializerInstances = new Dictionary<Type, object>(); 70 71 try { 71 72 var map = new Dictionary<Type, object>(); … … 74 75 typeIds.Add(typeMapping.Id, type); 75 76 Type serializerType = TypeLoader.Load(typeMapping.Serializer); 76 map.Add(type, Activator.CreateInstance(serializerType, true)); 77 object serializer; 78 if (serializerInstances.ContainsKey(serializerType)) 79 serializer = serializerInstances[serializerType]; 80 else 81 serializer = Activator.CreateInstance(serializerType, true); 82 map.Add(type, serializer); 77 83 } 78 84 return map; … … 82 88 throw new PersistenceException( 83 89 "The serialization type cache could not be loaded.\r\n" + 84 "This usualy happens when you are missing an Assembly /Plugin.", e);90 "This usualy happens when you are missing an Assembly or Plugin.", e); 85 91 } 86 92 } … … 113 119 private void CompositeStartHandler(BeginToken token) { 114 120 Type type = typeIds[(int)token.TypeId]; 115 ICompositeSerializer compositeSerializer = null; 116 if (serializerMapping.ContainsKey(type)) 117 compositeSerializer = serializerMapping[type] as ICompositeSerializer; 118 if (compositeSerializer == null) 119 throw new PersistenceException(String.Format( 120 "No suitable method for deserialization of type \"{0}\" found.", 121 type.VersionInvariantName())); 122 parentStack.Push(new Midwife(type, compositeSerializer, token.Id)); 121 try { 122 parentStack.Push(new Midwife(type, (ICompositeSerializer)serializerMapping[type], token.Id)); 123 } catch (Exception e) { 124 if (e is InvalidCastException || e is KeyNotFoundException) { 125 throw new PersistenceException(String.Format( 126 "Invalid composite serializer configuration for type \"{0}\".", 127 type.AssemblyQualifiedName), e); 128 } else { 129 throw new PersistenceException(String.Format( 130 "Unexpected exception while trying to compose object of type \"{0}\".", 131 type.AssemblyQualifiedName), e); 132 } 133 } 123 134 } 124 135 … … 134 145 private void PrimitiveHandler(PrimitiveToken token) { 135 146 Type type = typeIds[(int)token.TypeId]; 136 object value = ((IPrimitiveSerializer)serializerMapping[type]).Parse(token.SerialData); 137 if (token.Id != null) 138 id2obj[(int)token.Id] = value; 139 SetValue(token.Name, value); 147 try { 148 object value = ((IPrimitiveSerializer)serializerMapping[type]).Parse(token.SerialData); 149 if (token.Id != null) 150 id2obj[(int)token.Id] = value; 151 SetValue(token.Name, value); 152 } catch (Exception e) { 153 if (e is InvalidCastException || e is KeyNotFoundException) { 154 throw new PersistenceException(String.Format( 155 "Invalid primitive serializer configuration for type \"{0}\".", 156 type.AssemblyQualifiedName), e); 157 } else { 158 throw new PersistenceException(String.Format( 159 "Unexpected exception while trying to parse object of type \"{0}\".", 160 type.AssemblyQualifiedName), e); 161 } 162 } 140 163 } 141 164
Note: See TracChangeset
for help on using the changeset viewer.