- Timestamp:
- 03/09/09 15:16:47 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/New Persistence Exploration/Persistence/Persistence/Serializer.cs
r1314 r1317 11 11 private Dictionary<object, int> obj2id; 12 12 private Dictionary<Type, IPrimitiveSerializer> primitiveSerializers; 13 private List<ICompoundSerializer> c ustomSerializers;13 private List<ICompoundSerializer> compoundSerializers; 14 14 15 public Serializer(object obj, IEnumerable<IPrimitiveSerializer> primitiveSerializers) : 16 this(obj, primitiveSerializers, "ROOT") { } 15 public Serializer(object obj, 16 IEnumerable<IPrimitiveSerializer> primitiveSerializers, 17 IEnumerable<ICompoundSerializer> compoundSerializers) : 18 this(obj, primitiveSerializers, compoundSerializers, "ROOT") { } 17 19 18 public Serializer(object obj, IEnumerable<IPrimitiveSerializer> primitiveSerializers, string rootName) { 20 public Serializer(object obj, 21 IEnumerable<IPrimitiveSerializer> primitiveSerializers, 22 IEnumerable<ICompoundSerializer> compoundSerializers, string rootName) { 19 23 this.obj = obj; 20 24 this.rootName = rootName; … … 23 27 this.primitiveSerializers.Add(serializer.Type, serializer); 24 28 } 25 this.customSerializers = new List<ICompoundSerializer>(); 26 customSerializers.Add(new EnumerableSerializer()); 27 customSerializers.Add(new ArraySerializer()); 29 this.compoundSerializers = new List<ICompoundSerializer>(compoundSerializers); 28 30 this.obj2id = new Dictionary<object, int>(); 29 31 obj2id.Add(new object(), 0); … … 54 56 this.obj2id.Add(value, id); 55 57 yield return new BeginToken(accessor, id); 56 ICompoundSerializer customSerializer = this.FindC ustomSerializer(value.GetType());58 ICompoundSerializer customSerializer = this.FindCompoundSerializer(value.GetType()); 57 59 if (customSerializer != null) { 58 60 foreach (object obj in customSerializer.Serialize(value)) { … … 62 64 } 63 65 } else { // composite serialization 66 int nSubComponents = 0; 64 67 foreach (KeyValuePair<string, DataMemberAccessor> mapping in 65 68 StorableAttribute.GetAutostorableAccessors(value)) { 66 IEnumerator<ISerializationToken> iterator = this.Serialize(mapping.Value); 67 while (iterator.MoveNext()) 69 nSubComponents += 1; 70 IEnumerator<ISerializationToken> iterator = this.Serialize(mapping.Value); 71 while (iterator.MoveNext()) { 68 72 yield return iterator.Current; 73 } 74 } 75 if (nSubComponents == 0) { 76 throw new ApplicationException(String.Format( 77 "Composite value of type \"{0}\" contains no subcomponents", 78 value.GetType().FullName)); 69 79 } 70 80 } … … 73 83 } 74 84 75 private ICompoundSerializer FindC ustomSerializer(Type type) {76 foreach (ICompoundSerializer s in c ustomSerializers) {85 private ICompoundSerializer FindCompoundSerializer(Type type) { 86 foreach (ICompoundSerializer s in compoundSerializers) { 77 87 if (s.CanSerialize(type)) 78 88 return s;
Note: See TracChangeset
for help on using the changeset viewer.