1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Collections;
|
---|
4 | using System.IO;
|
---|
5 | using System.Reflection;
|
---|
6 |
|
---|
7 | namespace Persistence.Test {
|
---|
8 |
|
---|
9 | public class RootBase {
|
---|
10 | [Storable] private string baseString = "Serial";
|
---|
11 | }
|
---|
12 |
|
---|
13 | public class Root : RootBase {
|
---|
14 | [Storable]
|
---|
15 | public int[] i = new[] { 3, 4, 5, 6 };
|
---|
16 | [Storable]
|
---|
17 | public string s;
|
---|
18 | [Storable]
|
---|
19 | public ArrayList intArray = new ArrayList(new[] { 1, 2, 3 });
|
---|
20 | [Storable]
|
---|
21 | public List<int> intList = new List<int>(new[] { 321, 312, 321 });
|
---|
22 | [Storable]
|
---|
23 | public Custom c;
|
---|
24 | [Storable]
|
---|
25 | public List<Root> selfReferences;
|
---|
26 | [Storable]
|
---|
27 | public double[,] multiDimArray = new double[,] { { 1, 2, 3 }, { 3, 4, 5 } };
|
---|
28 | [Storable]
|
---|
29 | public bool boolean = true;
|
---|
30 | [Storable]
|
---|
31 | public DateTime dateTime;
|
---|
32 | [Storable]
|
---|
33 | public KeyValuePair<string, int> kvp = new KeyValuePair<string, int>("Serial", 123);
|
---|
34 | [Storable]
|
---|
35 | public Dictionary<string, int> dict = new Dictionary<string, int>();
|
---|
36 | [Storable(DefaultValue = "default")]
|
---|
37 | public string uninitialized;
|
---|
38 | }
|
---|
39 |
|
---|
40 | public class Custom {
|
---|
41 | [Storable]
|
---|
42 | public int i;
|
---|
43 | [Storable]
|
---|
44 | public Root r;
|
---|
45 | [Storable]
|
---|
46 | public string name = "Serial";
|
---|
47 | }
|
---|
48 |
|
---|
49 | public class CloneableRoot {
|
---|
50 | public int[] i = new[] { 3, 4, 5, 6 };
|
---|
51 | public string s;
|
---|
52 | public ArrayList intArray = new ArrayList(new[] { 1, 2, 3 });
|
---|
53 | public List<int> intList = new List<int>(new[] { 321, 312, 321 });
|
---|
54 | public CloneableCustom c;
|
---|
55 | public List<CloneableRoot> selfReferences;
|
---|
56 | public double[,] multiDimArray = new double[,] { { 1, 2, 3 }, { 3, 4, 5 } };
|
---|
57 | public bool boolean = true;
|
---|
58 | public DateTime dateTime;
|
---|
59 | public KeyValuePair<string, int> kvp = new KeyValuePair<string, int>("test key", 123);
|
---|
60 | public Dictionary<string, int> dict = new Dictionary<string, int>();
|
---|
61 | public object Clone(Dictionary<object, object> twins) {
|
---|
62 | if (twins.ContainsKey(this))
|
---|
63 | return twins[this];
|
---|
64 | CloneableRoot cr = new CloneableRoot();
|
---|
65 | twins.Add(this, cr);
|
---|
66 | cr.i = i;
|
---|
67 | cr.s = s;
|
---|
68 | cr.intArray = new ArrayList(intArray);
|
---|
69 | cr.intList = new List<int>(intList);
|
---|
70 | cr.c = (CloneableCustom)c.Clone(twins);
|
---|
71 | cr.selfReferences = new List<CloneableRoot>();
|
---|
72 | for (int j = 0; j < selfReferences.Count; j++) {
|
---|
73 | cr.selfReferences.Add(this);
|
---|
74 | }
|
---|
75 | cr.multiDimArray = (double[,])multiDimArray.Clone();
|
---|
76 | cr.dateTime = new DateTime(dateTime.Ticks);
|
---|
77 | cr.kvp = new KeyValuePair<string, int>(kvp.Key, kvp.Value);
|
---|
78 | cr.dict = new Dictionary<string, int>(dict);
|
---|
79 | return cr;
|
---|
80 | }
|
---|
81 | }
|
---|
82 |
|
---|
83 | public class CloneableCustom {
|
---|
84 | public int i;
|
---|
85 | public CloneableRoot r;
|
---|
86 | public string name = "Serial";
|
---|
87 | public object Clone(Dictionary<object, object> twins) {
|
---|
88 | if (twins.ContainsKey(this))
|
---|
89 | return twins[this];
|
---|
90 | CloneableCustom cc = new CloneableCustom();
|
---|
91 | twins.Add(this, cc);
|
---|
92 | cc.i = i;
|
---|
93 | cc.r = (CloneableRoot)r.Clone(twins);
|
---|
94 | cc.name = name;
|
---|
95 | return cc;
|
---|
96 | }
|
---|
97 | }
|
---|
98 |
|
---|
99 | public class Manager {
|
---|
100 |
|
---|
101 | private DateTime lastLoadTime;
|
---|
102 | [Storable]
|
---|
103 | private DateTime lastLoadTimePersistence {
|
---|
104 | get { return lastLoadTime; }
|
---|
105 | // ReSharper disable ValueParameterNotUsed
|
---|
106 | set { lastLoadTime = DateTime.Now; }
|
---|
107 | // ReSharper restore ValueParameterNotUsed
|
---|
108 | }
|
---|
109 | [Storable]
|
---|
110 | private double? dbl;
|
---|
111 | }
|
---|
112 |
|
---|
113 | public class StorableObject {
|
---|
114 |
|
---|
115 | [Storable]
|
---|
116 | Dictionary<int, string> dict;
|
---|
117 |
|
---|
118 | public void Init() {
|
---|
119 | dict = new Dictionary<int, string>();
|
---|
120 | for (int i = 0; i < 1000000; i++) {
|
---|
121 | dict.Add(i, i.ToString());
|
---|
122 | }
|
---|
123 | }
|
---|
124 | }
|
---|
125 |
|
---|
126 | public class CloneableObject : ICloneable {
|
---|
127 |
|
---|
128 | Dictionary<int, string> dict;
|
---|
129 |
|
---|
130 | public void Init() {
|
---|
131 | dict = new Dictionary<int, string>();
|
---|
132 | for (int i = 0; i < 1000000; i++) {
|
---|
133 | dict.Add(i, i.ToString());
|
---|
134 | }
|
---|
135 | }
|
---|
136 | public object Clone() {
|
---|
137 | CloneableObject clone = new CloneableObject{
|
---|
138 | dict = new Dictionary<int, string>(dict)
|
---|
139 | };
|
---|
140 | return clone;
|
---|
141 | }
|
---|
142 | }
|
---|
143 | }
|
---|