- Timestamp:
- 03/16/09 17:46:28 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/New Persistence Exploration/Persistence/Persistence/DeSerializer.cs
r1348 r1349 1 1 using System.Collections.Generic; 2 2 using System; 3 using System.Reflection;4 using System.Text;5 3 6 4 namespace Persistence { … … 64 62 private readonly Dictionary<Type, Handler> handlers; 65 63 private readonly Stack<IAccessibleObject> compositeStack; 66 67 private readonly Dictionary<Type, IFormatter> primitiveSerializers; 68 private readonly List<IDecomposer> customSerializers; 64 private readonly PersistenceConfiguration persistenceConfiguration; 69 65 70 66 delegate void Thunk(); 71 67 private List<Thunk> finalFixes; 72 68 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; 80 73 id2obj = new Dictionary<int, object>(); 81 74 compositeStack = new Stack<IAccessibleObject>(); … … 86 79 {typeof (Reference), ReferenceHandler}, 87 80 {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 }; 94 82 } 95 83 … … 108 96 CompositeStart start = (CompositeStart)token; 109 97 object instance; 110 if ( FindCompoundSerializer(start.Type) != null) {98 if (persistenceConfiguration.GetDecomposer(start.Type) != null) { 111 99 instance = new ParentReference(); 112 100 compositeStack.Push(new CustomObject(instance)); … … 121 109 } 122 110 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); 125 113 if (decomposer != null) { 126 114 CustomObject customObject = (CustomObject)compositeStack.Pop(); … … 135 123 SetValue(end.Name, compositeObject.Obj); 136 124 } 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 } 145 126 private void PrimitiveHandler(IParseToken token) { 146 127 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); 148 131 if ( ! value.GetType().IsValueType ) 149 132 id2obj[(int)primitive.Id] = value;
Note: See TracChangeset
for help on using the changeset viewer.