Changeset 1329 for branches/New Persistence Exploration/Persistence
- Timestamp:
- 03/12/09 12:17:30 (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
- Property svn:ignore
-
old new 2 2 .gitignore 3 3 *.suo 4 _ReSharper.Persistence
-
- Property svn:ignore
-
branches/New Persistence Exploration/Persistence/Persistence.sln
r1321 r1329 3 3 # Visual Studio 2008 4 4 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Persistence", "Persistence\Persistence.csproj", "{102BC7D3-0EF9-439C-8F6D-96FF0FDB8E1B}" 5 EndProject6 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PersistenceTest", "PersistenceTest\PersistenceTest.csproj", "{019D994A-9E37-4A4C-BBDD-914AB9A9634C}"7 5 EndProject 8 6 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2F65B17D-22F7-4A48-8762-74BB8BE3E0E5}" … … 29 27 {102BC7D3-0EF9-439C-8F6D-96FF0FDB8E1B}.Release|Any CPU.Build.0 = Release|Any CPU 30 28 {102BC7D3-0EF9-439C-8F6D-96FF0FDB8E1B}.Release|x86.ActiveCfg = Release|Any CPU 31 {019D994A-9E37-4A4C-BBDD-914AB9A9634C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU32 {019D994A-9E37-4A4C-BBDD-914AB9A9634C}.Debug|Any CPU.Build.0 = Debug|Any CPU33 {019D994A-9E37-4A4C-BBDD-914AB9A9634C}.Debug|x86.ActiveCfg = Debug|Any CPU34 {019D994A-9E37-4A4C-BBDD-914AB9A9634C}.Release|Any CPU.ActiveCfg = Release|Any CPU35 {019D994A-9E37-4A4C-BBDD-914AB9A9634C}.Release|Any CPU.Build.0 = Release|Any CPU36 {019D994A-9E37-4A4C-BBDD-914AB9A9634C}.Release|x86.ActiveCfg = Release|Any CPU37 29 EndGlobalSection 38 30 GlobalSection(SolutionProperties) = preSolution -
branches/New Persistence Exploration/Persistence/Persistence/DeSerializer.cs
r1318 r1329 15 15 16 16 class CustomObject : IAccessibleObject { 17 public object Obj { get { return this.obj; } } 18 private object obj; 19 public List<object> customValues; 17 public object Obj { get; private set; } 18 public readonly List<object> customValues; 20 19 public CustomObject(object obj) { 21 this.obj = obj;22 this.customValues = new List<object>();20 Obj = obj; 21 customValues = new List<object>(); 23 22 } 24 23 public void AddValue(object value) { … … 27 26 public Setter GetSetter(string name) { 28 27 int index = customValues.Count-1; 29 return (value)=> customValues[index] = value;28 return value => customValues[index] = value; 30 29 } 31 30 } 32 31 33 32 class CompositeObject : IAccessibleObject { 34 public object Obj { get { return this.obj; } } 35 public object obj; 36 public Dictionary<string, DataMemberAccessor> accessorDict; 33 public object Obj { get; private set; } 34 public readonly Dictionary<string, DataMemberAccessor> accessorDict; 37 35 public CompositeObject(object obj, Dictionary<string, DataMemberAccessor> accessorDict) { 38 this.obj = obj;36 Obj = obj; 39 37 this.accessorDict = new Dictionary<string, DataMemberAccessor>(); 40 38 foreach (KeyValuePair<string, DataMemberAccessor> pair in accessorDict) { … … 47 45 accessorDict[name].Set(value); 48 46 } 49 public void SetAllDefaultValues() {50 throw new NotImplementedException();51 }52 47 public Setter GetSetter(string name) { 53 return (value)=> accessorDict[name].Set(value);48 return value => accessorDict[name].Set(value); 54 49 } 55 50 } … … 57 52 private delegate void Handler(IParseToken token); 58 53 59 private Dictionary<int, object> id2obj;60 private Dictionary<Type, Handler> handlers;61 private Stack<IAccessibleObject> compositeStack;54 private readonly Dictionary<int, object> id2obj; 55 private readonly Dictionary<Type, Handler> handlers; 56 private readonly Stack<IAccessibleObject> compositeStack; 62 57 63 private Dictionary<Type, IPrimitiveSerializer> primitiveSerializers;64 private List<ICompoundSerializer> customSerializers;58 private readonly Dictionary<Type, IPrimitiveSerializer> primitiveSerializers; 59 private readonly List<ICompoundSerializer> customSerializers; 65 60 66 61 delegate void Thunk(); … … 76 71 id2obj = new Dictionary<int, object>(); 77 72 compositeStack = new Stack<IAccessibleObject>(); 78 handlers = new Dictionary<Type, Handler>(); 79 handlers.Add(typeof(CompositeStart), new Handler(CompositeStartHandler)); 80 handlers.Add(typeof(CompositeEnd), new Handler(CompositeEndHandler)); 81 handlers.Add(typeof(Primitive), new Handler(PrimitiveHandler)); 82 handlers.Add(typeof(Reference), new Handler(ReferenceHandler)); 83 handlers.Add(typeof(Null), new Handler(NullHandler)); 73 handlers = new Dictionary<Type, Handler> { 74 {typeof (CompositeStart), CompositeStartHandler}, 75 {typeof (CompositeEnd), CompositeEndHandler}, 76 {typeof (Primitive), PrimitiveHandler}, 77 {typeof (Reference), ReferenceHandler}, 78 {typeof (Null), NullHandler} 79 }; 84 80 this.primitiveSerializers = new Dictionary<Type, IPrimitiveSerializer>(); 85 81 foreach (IPrimitiveSerializer ps in primitiveSerializers) { … … 90 86 91 87 public object DeSerialize(IEnumerable<IParseToken> tokens) { 92 this.finalFixes = new List<Thunk>();88 finalFixes = new List<Thunk>(); 93 89 foreach (IParseToken token in tokens) { 94 90 handlers[token.GetType()].Invoke(token); 95 91 } 96 foreach (Thunk fix in this.finalFixes) {92 foreach (Thunk fix in finalFixes) { 97 93 fix(); 98 94 } … … 102 98 private void CompositeStartHandler(IParseToken token) { 103 99 CompositeStart start = (CompositeStart)token; 104 object instance = null;105 if ( this.FindCompoundSerializer(start.Type) != null) {100 object instance; 101 if (FindCompoundSerializer(start.Type) != null) { 106 102 instance = new ParentReference(); 107 103 compositeStack.Push(new CustomObject(instance)); … … 117 113 private void CompositeEndHandler(IParseToken token) { 118 114 CompositeEnd end = (CompositeEnd)token; 119 ICompoundSerializer customSerializer = this.FindCompoundSerializer(end.Type);115 ICompoundSerializer customSerializer = FindCompoundSerializer(end.Type); 120 116 if (customSerializer != null) { 121 117 CustomObject customObject = (CustomObject)compositeStack.Pop(); 122 118 object deserializedObject = 123 119 customSerializer.DeSerialize(customObject.customValues, end.Type); 124 this.id2obj[end.Id] = deserializedObject;125 this.SetValue(end.Name, deserializedObject);120 id2obj[end.Id] = deserializedObject; 121 SetValue(end.Name, deserializedObject); 126 122 } else { 127 123 CompositeObject compositeObject = (CompositeObject)compositeStack.Pop(); 128 this.SetValue(end.Name, compositeObject.obj);124 SetValue(end.Name, compositeObject.Obj); 129 125 } 130 126 } … … 143 139 private void ReferenceHandler(IParseToken token) { 144 140 Reference reference = (Reference)token; 145 object referredObject = this.id2obj[reference.Id];146 this.SetValue(reference.Name, this.id2obj[reference.Id]);141 object referredObject = id2obj[reference.Id]; 142 SetValue(reference.Name, id2obj[reference.Id]); 147 143 if (referredObject is ParentReference) { 148 144 Setter set = compositeStack.Peek().GetSetter(reference.Name); 149 145 int id = reference.Id; 150 this.finalFixes.Add(() => set(id2obj[id]));146 finalFixes.Add(() => set(id2obj[id])); 151 147 } 152 148 } 153 149 private void NullHandler(IParseToken token) { 154 150 Null nil = (Null)token; 155 this.SetValue(nil.Name, null);151 SetValue(nil.Name, null); 156 152 } 157 153 private void SetValue(string name, object value) { -
branches/New Persistence Exploration/Persistence/Persistence/Persistence.csproj
r1324 r1329 58 58 <Compile Include="Tokens.cs" /> 59 59 <Compile Include="Util.cs" /> 60 <Compile Include=" StorableAttributeTests.cs" />60 <Compile Include="Test\StorableAttributeTests.cs" /> 61 61 <Compile Include="StorableAttribute.cs" /> 62 62 <Compile Include="Test\NewSerializationTest.cs" /> 63 <Compile Include=" SerializationTest.cs" />63 <Compile Include="Test\SerializationTest.cs" /> 64 64 <Compile Include="XmlFormatter.cs" /> 65 65 <Compile Include="XmlParser.cs" /> -
branches/New Persistence Exploration/Persistence/Persistence/Test/NewSerializationTest.cs
r1323 r1329 26 26 public DateTime dateTime; 27 27 [Storable] 28 public KeyValuePair<string, int> kvp = new KeyValuePair<string, int>(" test key", 123);28 public KeyValuePair<string, int> kvp = new KeyValuePair<string, int>("Serial", 123); 29 29 [Storable] 30 30 public Dictionary<string, int> dict = new Dictionary<string, int>(); … … 241 241 242 242 public static void Main() { 243 //Test1();243 Test1(); 244 244 //Test2(); 245 245 //SpeedTest(); 246 SpeedTest2();246 //SpeedTest2(); 247 247 Console.In.ReadLine(); 248 248 } -
branches/New Persistence Exploration/Persistence/Persistence/Util.cs
r1324 r1329 3 3 using System.Text; 4 4 using System.Reflection; 5 using System.Collections;6 5 7 6 namespace Persistence { … … 31 30 return AutoFormat(o, recursive, visitedObjects); 32 31 } 33 private static string AutoFormat(object o, bool recursive, Dictionary<object, int> visitedObjects) {32 private static string AutoFormat(object o, bool recursive, IDictionary<object, int> visitedObjects) { 34 33 string s = o as string; 35 34 if (s != null) … … 40 39 if (visitedObjects.ContainsKey(o)) { 41 40 return o.ToString(); 42 } else { 43 visitedObjects.Add(o, 0); 44 } 41 } 42 visitedObjects.Add(o, 0); 45 43 if (o.ToString() != o.GetType().ToString()) { 46 44 return o.ToString(); … … 58 56 sb.Append("="); 59 57 if (recursive) { 60 sb.Append(AutoFormat( ((FieldInfo)mInfo).GetValue(o), true, visitedObjects));58 sb.Append(AutoFormat(fInfo.GetValue(o), true, visitedObjects)); 61 59 } else { 62 sb.Append( ((FieldInfo)mInfo).GetValue(o));60 sb.Append(fInfo.GetValue(o)); 63 61 } 64 62 sb.Append(", ");
Note: See TracChangeset
for help on using the changeset viewer.