Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4175


Ignore:
Timestamp:
08/06/10 16:59:13 (14 years ago)
Author:
epitzer
Message:

Properly copy serializers when initializing global configuration. (#1136)

Location:
trunk/sources/HeuristicLab.Persistence/3.3
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Persistence/3.3/Core/ConfigurationService.cs

    r4068 r4175  
    9494      try {
    9595        TryLoadSettings();
    96       }
    97       catch (Exception e) {
     96      } catch (Exception e) {
    9897        if (throwOnError) {
    9998          throw new PersistenceException("Could not load persistence settings.", e);
     
    162161          if (a != defaultAssembly)
    163162            DiscoverFrom(a);
    164       }
    165       catch (AppDomainUnloadedException x) {
     163      } catch (AppDomainUnloadedException x) {
    166164        Logger.Warn("could not get list of assemblies, AppDomain has already been unloaded", x);
    167165      }
     
    207205          }
    208206        }
    209       }
    210       catch (ReflectionTypeLoadException e) {
     207      } catch (ReflectionTypeLoadException e) {
    211208        Logger.Warn("could not analyse assembly: " + a.FullName, e);
    212209      }
     
    223220        foreach (IPrimitiveSerializer f in PrimitiveSerializers[format.SerialDataType]) {
    224221          if (!primitiveConfig.ContainsKey(f.SourceType))
    225             primitiveConfig.Add(f.SourceType, f);
     222            primitiveConfig.Add(f.SourceType, (IPrimitiveSerializer)Activator.CreateInstance(f.GetType()));
    226223        }
    227224      } else {
     
    234231        format,
    235232        primitiveConfig.Values,
    236         CompositeSerializers.Where((d) => d.Priority > 0));
     233        CompositeSerializers.Where((d) => d.Priority > 0).Select(d => (ICompositeSerializer)Activator.CreateInstance(d.GetType())));
    237234    }
    238235
  • trunk/sources/HeuristicLab.Persistence/3.3/Core/DeSerializer.cs

    r4068 r4175  
    8585    private readonly Stack<Midwife> parentStack;
    8686    private readonly Dictionary<int, Type> typeIds;
     87    private Dictionary<Type, object> serializerInstances;
    8788
    8889    /// <summary>
     
    9899      typeIds = new Dictionary<int, Type>();
    99100      serializerMapping = new Dictionary<Type, object>();
     101      serializerInstances = new Dictionary<Type, object>();
    100102      foreach (var typeMapping in typeCache) {
    101103        AddTypeInfo(typeMapping);
    102104      }
    103105    }
    104 
    105     private Dictionary<Type, object> serializerInstances = new Dictionary<Type, object>();
    106106
    107107    /// <summary>
     
    117117        Type serializerType = TypeLoader.Load(typeMapping.Serializer);
    118118        object serializer;
    119         if (serializerInstances.ContainsKey(serializerType))
     119        if (serializerInstances.ContainsKey(serializerType)) {
    120120          serializer = serializerInstances[serializerType];
    121         else
     121        } else {
    122122          serializer = Activator.CreateInstance(serializerType, true);
     123          serializerInstances.Add(serializerType, serializer);
     124        }
    123125        serializerMapping.Add(type, serializer);
    124       }
    125       catch (PersistenceException) {
     126      } catch (PersistenceException) {
    126127        throw;
    127       }
    128       catch (Exception e) {
     128      } catch (Exception e) {
    129129        throw new PersistenceException(string.Format(
    130130          "Could not add type info for {0} ({1})",
     
    181181      try {
    182182        parentStack.Push(new Midwife(type, (ICompositeSerializer)serializerMapping[type], token.Id));
    183       }
    184       catch (Exception e) {
     183      } catch (Exception e) {
    185184        if (e is InvalidCastException || e is KeyNotFoundException) {
    186185          throw new PersistenceException(String.Format(
     
    211210          id2obj[(int)token.Id] = value;
    212211        SetValue(token.Name, value);
    213       }
    214       catch (Exception e) {
     212      } catch (Exception e) {
    215213        if (e is InvalidCastException || e is KeyNotFoundException) {
    216214          throw new PersistenceException(String.Format(
  • trunk/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/Storable/StorableSerializer.cs

    r4068 r4175  
    4040  [StorableClass]
    4141  public sealed class StorableSerializer : ICompositeSerializer {
     42
     43    public StorableSerializer() {
     44      accessorListCache = new AccessorListCache();
     45      accessorCache = new AccessorCache();
     46      constructorCache = new Dictionary<Type, Constructor>();
     47      hookCache = new Dictionary<HookDesignator, List<StorableReflection.Hook>>();
     48    }
    4249
    4350    #region ICompositeSerializer implementation
     
    122129      try {
    123130        return GetConstructor(type)();
    124       }
    125       catch (TargetInvocationException x) {
     131      } catch (TargetInvocationException x) {
    126132        throw new PersistenceException(
    127133          "Could not instantiate storable object: Encountered exception during constructor call",
     
    174180    private sealed class AccessorListCache : Dictionary<Type, IEnumerable<DataMemberAccessor>> { }
    175181    private sealed class AccessorCache : Dictionary<MemberInfo, DataMemberAccessor> { }
     182    private delegate object Constructor();
    176183
    177184    #endregion
     
    179186    #region caches
    180187
    181     private AccessorListCache accessorListCache = new AccessorListCache();
    182     private AccessorCache accessorCache = new AccessorCache();
    183 
    184     private delegate object Constructor();
    185 
    186     private Dictionary<Type, Constructor> constructorCache =
    187       new Dictionary<Type, Constructor>();
    188 
    189     private Dictionary<HookDesignator, List<StorableReflection.Hook>> hookCache =
    190       new Dictionary<HookDesignator, List<StorableReflection.Hook>>();
     188    private AccessorListCache accessorListCache;
     189    private AccessorCache accessorCache;
     190    private Dictionary<Type, Constructor> constructorCache;
     191    private Dictionary<HookDesignator, List<StorableReflection.Hook>> hookCache;
    191192
    192193    #endregion
Note: See TracChangeset for help on using the changeset viewer.