Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/16/09 17:46:28 (15 years ago)
Author:
epitzer
Message:

Central persistence configuration class. (#506)

File:
1 edited

Legend:

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

    r1348 r1349  
    11using System.Collections.Generic;
    22using System;
    3 using System.Reflection;
    4 using System.Text;
    53
    64namespace Persistence {
     
    6462    private readonly Dictionary<Type, Handler> handlers;
    6563    private readonly Stack<IAccessibleObject> compositeStack;
    66 
    67     private readonly Dictionary<Type, IFormatter> primitiveSerializers;
    68     private readonly List<IDecomposer> customSerializers;
     64    private readonly PersistenceConfiguration persistenceConfiguration;
    6965
    7066    delegate void Thunk();
    7167    private List<Thunk> finalFixes;
    7268
    73     public DeSerializer() : this(
    74       InterfaceInstantiatior.InstantiateAll<IFormatter>(),
    75       InterfaceInstantiatior.InstantiateAll<IDecomposer>()) {}   
    76 
    77     public DeSerializer(
    78         IEnumerable<IFormatter> primitiveSerializers,
    79         IEnumerable<IDecomposer> customSerializers) {
     69    public DeSerializer() : this(PersistenceConfiguration.Instance) {}
     70 
     71    public DeSerializer(PersistenceConfiguration persistenceConfiguration) {
     72      this.persistenceConfiguration = persistenceConfiguration;
    8073      id2obj = new Dictionary<int, object>();
    8174      compositeStack = new Stack<IAccessibleObject>();
     
    8679                     {typeof (Reference), ReferenceHandler},
    8780                     {typeof (Null), NullHandler}
    88                    };
    89       this.primitiveSerializers = new Dictionary<Type, IFormatter>();
    90       foreach (IFormatter ps in primitiveSerializers) {
    91         this.primitiveSerializers.Add(ps.Type, ps);
    92       }
    93       this.customSerializers = new List<IDecomposer>(customSerializers);
     81                   };     
    9482    }
    9583
     
    10896      CompositeStart start = (CompositeStart)token;
    10997      object instance;
    110       if (FindCompoundSerializer(start.Type) != null) {
     98      if (persistenceConfiguration.GetDecomposer(start.Type) != null) {
    11199        instance = new ParentReference();
    112100        compositeStack.Push(new CustomObject(instance));       
     
    121109    }
    122110    private void CompositeEndHandler(IParseToken token) {
    123       CompositeEnd end = (CompositeEnd)token;
    124       IDecomposer decomposer = FindCompoundSerializer(end.Type);
     111      CompositeEnd end = (CompositeEnd)token;     
     112      IDecomposer decomposer = persistenceConfiguration.GetDecomposer(end.Type);
    125113      if (decomposer != null) {
    126114        CustomObject customObject = (CustomObject)compositeStack.Pop();
     
    135123        SetValue(end.Name, compositeObject.Obj);
    136124      }
    137     }
    138     private IDecomposer FindCompoundSerializer(Type type) {
    139       foreach (IDecomposer serializer in customSerializers) {
    140         if (serializer.CanSerialize(type))
    141           return serializer;
    142       }
    143       return null;
    144     }
     125    }   
    145126    private void PrimitiveHandler(IParseToken token) {
    146127      Primitive primitive = (Primitive)token;
    147       object value = primitiveSerializers[primitive.Type].DeSerialize(primitive.SerializedValue);
     128      object value = persistenceConfiguration
     129        .GetFormatter(XmlFormat.Instance, primitive.Type)
     130        .DeSerialize(primitive.SerializedValue);
    148131      if ( ! value.GetType().IsValueType )
    149132        id2obj[(int)primitive.Id] = value;
Note: See TracChangeset for help on using the changeset viewer.