Changeset 1362 for branches/New Persistence Exploration/Persistence/Persistence/Core/DeSerializer.cs
- Timestamp:
- 03/19/09 14:02:35 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/New Persistence Exploration/Persistence/Persistence/Core/DeSerializer.cs
r1361 r1362 75 75 76 76 private readonly Dictionary<int, object> id2obj; 77 private readonly Dictionary<Type, object> serializerMapping; 77 78 private readonly Dictionary<Type, Handler> handlers; 78 private readonly Stack<IAccessibleObject> parentStack; 79 private readonly Configuration configuration; 79 private readonly Stack<IAccessibleObject> parentStack; 80 80 private readonly Dictionary<int, Type> typeIds; 81 81 private List<Thunk> finalFixes; 82 82 83 83 public DeSerializer( 84 IEnumerable<KeyValuePair<string, int>> typeCache, 85 Configuration configuration) { 86 this.configuration = configuration; 84 IEnumerable<TypeMapping> typeCache) { 87 85 id2obj = new Dictionary<int, object>(); 88 86 parentStack = new Stack<IAccessibleObject>(); … … 95 93 }; 96 94 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 } 100 103 } 101 104 } … … 116 119 object instance; 117 120 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) { 119 125 instance = new ParentReference(); 120 126 parentStack.Push(new CustomComposite(instance)); … … 132 138 EndToken end = (EndToken)token; 133 139 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; 135 143 if (decomposer != null) { 136 144 CustomComposite customComposite = (CustomComposite)parentStack.Pop(); … … 150 158 PrimitiveToken primitive = (PrimitiveToken)token; 151 159 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); 155 161 if ( ! value.GetType().IsValueType ) 156 162 id2obj[(int)primitive.Id] = value; … … 172 178 NullReferenceToken nil = (NullReferenceToken)token; 173 179 SetValue(nil.Name, null); 174 } 180 } 175 181 176 182 private void SetValue(string name, object value) {
Note: See TracChangeset
for help on using the changeset viewer.