Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/19/09 14:02:35 (15 years ago)
Author:
epitzer
Message:

Add serializer class information to type cache. (#506)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/New Persistence Exploration/Persistence/Persistence/Core/DeSerializer.cs

    r1361 r1362  
    7575
    7676    private readonly Dictionary<int, object> id2obj;
     77    private readonly Dictionary<Type, object> serializerMapping;
    7778    private readonly Dictionary<Type, Handler> handlers;
    78     private readonly Stack<IAccessibleObject> parentStack;
    79     private readonly Configuration configuration;
     79    private readonly Stack<IAccessibleObject> parentStack;   
    8080    private readonly Dictionary<int, Type> typeIds;   
    8181    private List<Thunk> finalFixes;
    8282
    8383    public DeSerializer(
    84       IEnumerable<KeyValuePair<string, int>> typeCache,
    85       Configuration configuration) {
    86       this.configuration = configuration;
     84      IEnumerable<TypeMapping> typeCache) {     
    8785      id2obj = new Dictionary<int, object>();
    8886      parentStack = new Stack<IAccessibleObject>();
     
    9593                   };     
    9694      typeIds = new Dictionary<int, Type>();
    97       foreach ( var pair in typeCache ) {
    98         Type type = Type.GetType(pair.Key);
    99         typeIds.Add(pair.Value, type);
     95      serializerMapping = new Dictionary<Type, object>();
     96      foreach ( var typeMapping in typeCache ) {
     97        Type type = Type.GetType(typeMapping.TypeName);
     98        typeIds.Add(typeMapping.Id, type);
     99        if (typeMapping.Serializer != null) {
     100          Type serializerType = Type.GetType(typeMapping.Serializer);
     101          serializerMapping.Add(type, Activator.CreateInstance(serializerType, true));
     102        }
    100103      }
    101104    }
     
    116119      object instance;     
    117120      Type type = typeIds[(int)start.TypeId];
    118       if (configuration.GetDecomposer(type) != null) {
     121      IDecomposer decomposer = null;
     122      if ( serializerMapping.ContainsKey(type) )
     123        decomposer = serializerMapping[type] as IDecomposer;     
     124      if (decomposer != null) {
    119125        instance = new ParentReference();
    120126        parentStack.Push(new CustomComposite(instance));       
     
    132138      EndToken end = (EndToken)token;
    133139      Type type = typeIds[(int)end.TypeId];
    134       IDecomposer decomposer = configuration.GetDecomposer(type);
     140      IDecomposer decomposer = null;
     141      if (serializerMapping.ContainsKey(type))
     142        decomposer = serializerMapping[type] as IDecomposer;           
    135143      if (decomposer != null) {
    136144        CustomComposite customComposite = (CustomComposite)parentStack.Pop();
     
    150158      PrimitiveToken primitive = (PrimitiveToken)token;
    151159      Type type = typeIds[(int)primitive.TypeId];
    152       object value = configuration
    153         .GetFormatter(type)
    154         .Parse(primitive.SerialData);
     160      object value = ((IFormatter) serializerMapping[type]).Parse(primitive.SerialData);
    155161      if ( ! value.GetType().IsValueType )
    156162        id2obj[(int)primitive.Id] = value;
     
    172178      NullReferenceToken nil = (NullReferenceToken)token;
    173179      SetValue(nil.Name, null);
    174     }
     180    }   
    175181
    176182    private void SetValue(string name, object value) {
Note: See TracChangeset for help on using the changeset viewer.