Changeset 1321 for branches/New Persistence Exploration
- Timestamp:
- 03/09/09 18:36:38 (16 years ago)
- Location:
- branches/New Persistence Exploration/Persistence
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/New Persistence Exploration/Persistence/Persistence.sln
r1264 r1321 4 4 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Persistence", "Persistence\Persistence.csproj", "{102BC7D3-0EF9-439C-8F6D-96FF0FDB8E1B}" 5 5 EndProject 6 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PersistenceTest", "PersistenceTest\PersistenceTest.csproj", "{019D994A-9E37-4A4C-BBDD-914AB9A9634C}" 7 EndProject 8 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2F65B17D-22F7-4A48-8762-74BB8BE3E0E5}" 9 ProjectSection(SolutionItems) = preProject 10 LocalTestRun.testrunconfig = LocalTestRun.testrunconfig 11 Persistence.vsmdi = Persistence.vsmdi 12 EndProjectSection 13 EndProject 6 14 Global 15 GlobalSection(TestCaseManagementSettings) = postSolution 16 CategoryFile = Persistence.vsmdi 17 EndGlobalSection 7 18 GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 19 Debug|Any CPU = Debug|Any CPU … … 18 29 {102BC7D3-0EF9-439C-8F6D-96FF0FDB8E1B}.Release|Any CPU.Build.0 = Release|Any CPU 19 30 {102BC7D3-0EF9-439C-8F6D-96FF0FDB8E1B}.Release|x86.ActiveCfg = Release|Any CPU 31 {019D994A-9E37-4A4C-BBDD-914AB9A9634C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 32 {019D994A-9E37-4A4C-BBDD-914AB9A9634C}.Debug|Any CPU.Build.0 = Debug|Any CPU 33 {019D994A-9E37-4A4C-BBDD-914AB9A9634C}.Debug|x86.ActiveCfg = Debug|Any CPU 34 {019D994A-9E37-4A4C-BBDD-914AB9A9634C}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 {019D994A-9E37-4A4C-BBDD-914AB9A9634C}.Release|Any CPU.Build.0 = Release|Any CPU 36 {019D994A-9E37-4A4C-BBDD-914AB9A9634C}.Release|x86.ActiveCfg = Release|Any CPU 20 37 EndGlobalSection 21 38 GlobalSection(SolutionProperties) = preSolution -
branches/New Persistence Exploration/Persistence/Persistence/NewSerializationTest.cs
r1320 r1321 78 78 DeSerializer deSerializer = new DeSerializer(); 79 79 object o = deSerializer.DeSerialize(parser); 80 Root t = StorableAttribute.Clone(r); 80 81 Console.Out.WriteLine(Util.AutoFormat(o, true)); 81 82 } … … 95 96 DeSerializer deSerializer = new DeSerializer(); 96 97 object o = deSerializer.DeSerialize(parser); 97 Console.Out.WriteLine(Util.AutoFormat(o, true)); 98 Manager n = StorableAttribute.Clone(m); 99 Console.Out.WriteLine(Util.AutoFormat(o, true)); 98 100 } 99 101 100 102 public static void Main() { 101 //Test1();103 Test1(); 102 104 Test2(); 103 105 Console.In.ReadLine(); -
branches/New Persistence Exploration/Persistence/Persistence/StorableAttribute.cs
r1264 r1321 3 3 using System.Text; 4 4 using System.Reflection; 5 using System.Collections; 5 6 6 7 namespace Persistence { … … 44 45 } 45 46 return autoStorableAccessors; 47 } 48 49 private static MethodInfo MemberwiseClone; 50 51 public static StorableAttribute() { 52 foreach (MethodInfo mi in typeof(object).GetMethods(BindingFlags.Instance | BindingFlags.NonPublic)) { 53 if (mi.Name == "MemberwiseClone") { 54 MemberwiseClone = mi; 55 } 56 } 57 } 58 59 public static T Clone<T>(T obj) { 60 List<ICompoundSerializer> compoundSerializers = 61 InterfaceInstantiatior.InstantiateAll<ICompoundSerializer>(); 62 return Clone(obj, compoundSerializers); 63 } 64 65 public static T Clone<T>(T obj, IEnumerable<ICompoundSerializer> compoundSerializers) { 66 Dictionary<object, object> twins = new Dictionary<object, object>(); 67 return Clone(obj, twins, compoundSerializers); 46 68 } 69 70 public static T Clone<T>(T obj, Dictionary<object, object> twins, 71 IEnumerable<ICompoundSerializer> compoundSerializers) { 72 if (obj == null) 73 return default(T); 74 ValueType t = obj as ValueType; 75 if (t != null) { 76 return (T)obj; 77 } 78 if (twins.ContainsKey(obj)) 79 return (T)twins[obj]; 80 ICloneable c = obj as ICloneable; 81 if (c != null) { 82 T newClone = (T)c.Clone(); 83 twins[obj] = newClone; 84 return newClone; 85 } 86 T newInstance = (T)Activator.CreateInstance(obj.GetType()); 87 twins[obj] = newInstance; 88 Dictionary<string, DataMemberAccessor> oldAccessors = GetAutostorableAccessors(obj); 89 if (oldAccessors.Count == 0) { 90 foreach (ICompoundSerializer serializer in compoundSerializers) { 91 if ( serializer.CanSerialize(obj.GetType()) ) { 92 IEnumerable subObjects = serializer.Serialize(obj); 93 IEnumerable clonedSubObjects = Functional.Map(subObjects, 94 (x) => Clone(x, twins, compoundSerializers)); 95 return (T)serializer.DeSerialize(clonedSubObjects, obj.GetType()); 96 } 97 } 98 // TODO: fallback with memberwise clone? 99 throw new ApplicationException("cannot continue cloning, reached a dead end"); 100 } 101 Dictionary<string, DataMemberAccessor> newAccessors = GetAutostorableAccessors(newInstance); 102 foreach (KeyValuePair<string, DataMemberAccessor> nameAccess in oldAccessors) { 103 newAccessors[nameAccess.Key].Set(Clone(nameAccess.Value.Get(), twins, compoundSerializers)); 104 } 105 return newInstance; 106 } 47 107 } 48 108 -
branches/New Persistence Exploration/Persistence/Persistence/Util.cs
r1318 r1321 3 3 using System.Text; 4 4 using System.Reflection; 5 using System.Collections; 5 6 6 7 namespace Persistence { 8 public class Functional { 9 10 public delegate object Mapper(object x); 11 12 public static IEnumerable Map(IEnumerable enumeration, Mapper m) { 13 foreach (object t in enumeration) { 14 yield return m(t); 15 } 16 } 17 18 } 7 19 public class InterfaceInstantiatior { 8 20 public static List<T> InstantiateAll<T>() {
Note: See TracChangeset
for help on using the changeset viewer.