Changeset 1348
- Timestamp:
- 03/16/09 16:35:31 (16 years ago)
- Location:
- branches/New Persistence Exploration/Persistence
- Files:
-
- 2 added
- 2 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/New Persistence Exploration/Persistence/Persistence/DeSerializer.cs
r1339 r1348 1 1 using System.Collections.Generic; 2 2 using System; 3 namespace Persistence { 3 using System.Reflection; 4 using System.Text; 5 6 namespace Persistence { 4 7 5 8 public class DeSerializer { … … 62 65 private readonly Stack<IAccessibleObject> compositeStack; 63 66 64 private readonly Dictionary<Type, I PrimitiveSerializer> primitiveSerializers;65 private readonly List<I CompoundSerializer> customSerializers;67 private readonly Dictionary<Type, IFormatter> primitiveSerializers; 68 private readonly List<IDecomposer> customSerializers; 66 69 67 70 delegate void Thunk(); … … 69 72 70 73 public DeSerializer() : this( 71 InterfaceInstantiatior.InstantiateAll<I PrimitiveSerializer>(),72 InterfaceInstantiatior.InstantiateAll<I CompoundSerializer>()) {}74 InterfaceInstantiatior.InstantiateAll<IFormatter>(), 75 InterfaceInstantiatior.InstantiateAll<IDecomposer>()) {} 73 76 74 77 public DeSerializer( 75 IEnumerable<I PrimitiveSerializer> primitiveSerializers,76 IEnumerable<I CompoundSerializer> customSerializers) {78 IEnumerable<IFormatter> primitiveSerializers, 79 IEnumerable<IDecomposer> customSerializers) { 77 80 id2obj = new Dictionary<int, object>(); 78 81 compositeStack = new Stack<IAccessibleObject>(); … … 84 87 {typeof (Null), NullHandler} 85 88 }; 86 this.primitiveSerializers = new Dictionary<Type, I PrimitiveSerializer>();87 foreach (I PrimitiveSerializer ps in primitiveSerializers) {89 this.primitiveSerializers = new Dictionary<Type, IFormatter>(); 90 foreach (IFormatter ps in primitiveSerializers) { 88 91 this.primitiveSerializers.Add(ps.Type, ps); 89 92 } 90 this.customSerializers = new List<I CompoundSerializer>(customSerializers);93 this.customSerializers = new List<IDecomposer>(customSerializers); 91 94 } 92 95 … … 119 122 private void CompositeEndHandler(IParseToken token) { 120 123 CompositeEnd end = (CompositeEnd)token; 121 I CompoundSerializer compoundSerializer = FindCompoundSerializer(end.Type);122 if ( compoundSerializer != null) {124 IDecomposer decomposer = FindCompoundSerializer(end.Type); 125 if (decomposer != null) { 123 126 CustomObject customObject = (CustomObject)compositeStack.Pop(); 124 127 object deserializedObject = 125 compoundSerializer.DeSerialize(customObject.customValues, end.Type);128 decomposer.DeSerialize(customObject.customValues, end.Type); 126 129 if ( end.Id != null ) 127 130 id2obj[(int)end.Id] = deserializedObject; … … 133 136 } 134 137 } 135 private I CompoundSerializer FindCompoundSerializer(Type type) {136 foreach (I CompoundSerializer serializer in customSerializers) {138 private IDecomposer FindCompoundSerializer(Type type) { 139 foreach (IDecomposer serializer in customSerializers) { 137 140 if (serializer.CanSerialize(type)) 138 141 return serializer; -
branches/New Persistence Exploration/Persistence/Persistence/Persistence.csproj
r1338 r1348 56 56 <Compile Include="Properties\AssemblyInfo.cs" /> 57 57 <Compile Include="Serializer.cs" /> 58 <Compile Include=" CompoundSerializers.cs" />59 <Compile Include="Primitive Serializers.cs" />58 <Compile Include="Decomposers.cs" /> 59 <Compile Include="PrimitiveFormatters.cs" /> 60 60 <Compile Include="Test\NewSerializationTest.cs" /> 61 61 <Compile Include="Tokens.cs" /> -
branches/New Persistence Exploration/Persistence/Persistence/Serializer.cs
r1339 r1348 10 10 private readonly string rootName; 11 11 private readonly Dictionary<object, int> obj2id; 12 private readonly Dictionary<Type, I PrimitiveSerializer> primitiveSerializers;13 private readonly List<I CompoundSerializer> compoundSerializers;12 private readonly Dictionary<Type, IFormatter> primitiveSerializers; 13 private readonly List<IDecomposer> compoundSerializers; 14 14 private readonly Dictionary<Type, int> typeCache; 15 15 16 16 public Serializer(object obj) : 17 17 this(obj, 18 InterfaceInstantiatior.InstantiateAll<I PrimitiveSerializer>(),19 InterfaceInstantiatior.InstantiateAll<I CompoundSerializer>()) {}18 InterfaceInstantiatior.InstantiateAll<IFormatter>(), 19 InterfaceInstantiatior.InstantiateAll<IDecomposer>()) {} 20 20 21 21 public Serializer(object obj, 22 IEnumerable<I PrimitiveSerializer> primitiveSerializers,23 IEnumerable<I CompoundSerializer> compoundSerializers) :22 IEnumerable<IFormatter> primitiveSerializers, 23 IEnumerable<IDecomposer> compoundSerializers) : 24 24 this(obj, primitiveSerializers, compoundSerializers, "ROOT") { } 25 25 26 26 public Serializer(object obj, 27 IEnumerable<I PrimitiveSerializer> primitiveSerializers,28 IEnumerable<I CompoundSerializer> compoundSerializers, string rootName) {27 IEnumerable<IFormatter> primitiveSerializers, 28 IEnumerable<IDecomposer> compoundSerializers, string rootName) { 29 29 this.obj = obj; 30 30 this.rootName = rootName; 31 this.primitiveSerializers = new Dictionary<Type, I PrimitiveSerializer>();32 foreach (I PrimitiveSerializer serializer in primitiveSerializers) {31 this.primitiveSerializers = new Dictionary<Type, IFormatter>(); 32 foreach (IFormatter serializer in primitiveSerializers) { 33 33 this.primitiveSerializers.Add(serializer.Type, serializer); 34 34 } 35 this.compoundSerializers = new List<I CompoundSerializer>(compoundSerializers);35 this.compoundSerializers = new List<IDecomposer>(compoundSerializers); 36 36 obj2id = new Dictionary<object, int> {{new object(), 0}}; 37 37 typeCache = new Dictionary<Type, int>(); … … 48 48 while (iterator.MoveNext()) 49 49 yield return iterator.Current; 50 Console.WriteLine("TypeCache:f"); 51 foreach ( var pair in typeCache ) 52 Console.WriteLine(pair.Key); 50 Console.WriteLine("TypeCache:"); 51 foreach (var pair in typeCache) { 52 Console.WriteLine("<TYPE id=\"{0}\" AssemblyQualifiedName=\"{1}\">", 53 pair.Value, 54 pair.Key.AssemblyQualifiedName); 55 } 53 56 } 54 57 … … 86 89 87 90 yield return new BeginToken(accessor, id); 88 I CompoundSerializer customSerializer= FindCompoundSerializer(value.GetType());91 IDecomposer custom = FindCompoundSerializer(value.GetType()); 89 92 90 if (custom Serializer!= null) {91 foreach (object o in custom Serializer.Serialize(value)) {93 if (custom != null) { 94 foreach (object o in custom.Serialize(value)) { 92 95 IEnumerator<ISerializationToken> iterator = Serialize(new DataMemberAccessor(o)); 93 96 while (iterator.MoveNext()) … … 115 118 } 116 119 117 private I CompoundSerializer FindCompoundSerializer(Type type) {118 foreach (I CompoundSerializer s in compoundSerializers) {120 private IDecomposer FindCompoundSerializer(Type type) { 121 foreach (IDecomposer s in compoundSerializers) { 119 122 if (s.CanSerialize(type)) 120 123 return s; -
branches/New Persistence Exploration/Persistence/Persistence/StorableAttribute.cs
r1338 r1348 59 59 } 60 60 61 private readonly List<I CompoundSerializer> compoundSerializers;62 63 public CloningFactory(IEnumerable<I CompoundSerializer> compoundSerializers) {64 this.compoundSerializers = new List<I CompoundSerializer>(compoundSerializers);61 private readonly List<IDecomposer> compoundSerializers; 62 63 public CloningFactory(IEnumerable<IDecomposer> compoundSerializers) { 64 this.compoundSerializers = new List<IDecomposer>(compoundSerializers); 65 65 } 66 66 67 67 public CloningFactory() : 68 this(InterfaceInstantiatior.InstantiateAll<I CompoundSerializer>()) { }68 this(InterfaceInstantiatior.InstantiateAll<IDecomposer>()) { } 69 69 70 70 delegate object CloneMethod(object obj, Dictionary<object, object> twins); … … 106 106 if (type.GetConstructor(new[] { type }) != null) 107 107 return CopyConstructorCloneMethod.Create(type); 108 foreach (I CompoundSerializer serializer in compoundSerializers)108 foreach (IDecomposer serializer in compoundSerializers) 109 109 if (serializer.CanSerialize(type)) 110 110 return CompoundSerializerCloneMethod.Create(serializer, type, this); … … 128 128 129 129 class CompoundSerializerCloneMethod { 130 public static CloneMethod Create(I CompoundSerializer serializer,130 public static CloneMethod Create(IDecomposer serializer, 131 131 Type type, CloningFactory factory) { 132 132 return new CompoundSerializerCloneMethod(serializer, type, factory).method; 133 133 } 134 private readonly I CompoundSerializer serializer;134 private readonly IDecomposer serializer; 135 135 private readonly Type type; 136 136 private readonly CloningFactory factory; 137 public CompoundSerializerCloneMethod(I CompoundSerializer serializer,137 public CompoundSerializerCloneMethod(IDecomposer serializer, 138 138 Type type, CloningFactory factory) { 139 139 this.serializer = serializer; -
branches/New Persistence Exploration/Persistence/Test/NewSerializationTest.cs
r1338 r1348 120 120 } 121 121 122 public static void Main() { 123 int[] i = {1, 2, 3}; 124 object o = i; 125 Type type = o.GetType().BaseType.BaseType; 126 foreach (MemberInfo mi in type.GetMembers(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic )) { 127 if ( mi.MemberType == MemberTypes.Field || mi.MemberType == MemberTypes.Property ) 128 Console.WriteLine(mi.Name); 129 } 122 public static void Main() { 130 123 Test1(); 131 124 //Test2(); -
branches/New Persistence Exploration/Persistence/Test/Test.csproj
r1338 r1348 49 49 <Compile Include="NewSerializationTest.cs" /> 50 50 </ItemGroup> 51 <ItemGroup> 52 <Reference Include="System" /> 53 <Reference Include="System.Core"> 54 <RequiredTargetFramework>3.5</RequiredTargetFramework> 55 </Reference> 56 </ItemGroup> 51 57 </Project>
Note: See TracChangeset
for help on using the changeset viewer.