1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Text;
|
---|
4 | using System.Collections;
|
---|
5 | using System.IO;
|
---|
6 |
|
---|
7 | namespace Persistence {
|
---|
8 |
|
---|
9 | public class Root {
|
---|
10 |
|
---|
11 | [Storable]
|
---|
12 | public int[] i = new int[] { 3, 4, 5, 6 };
|
---|
13 | [Storable]
|
---|
14 | public string s;
|
---|
15 | [Storable]
|
---|
16 | public ArrayList intArray = new ArrayList(new int[] { 1, 2, 3 });
|
---|
17 | [Storable]
|
---|
18 | public List<int> intList = new List<int>(new int[] { 321, 312, 321 });
|
---|
19 | [Storable]
|
---|
20 | public Custom c;
|
---|
21 | [Storable]
|
---|
22 | public List<Root> selfReferences;
|
---|
23 | [Storable]
|
---|
24 | public double[,] multiDimArray = new double[,] { { 1, 2, 3 }, { 3, 4, 5 } };
|
---|
25 | [Storable]
|
---|
26 | public bool boolean = true;
|
---|
27 | [Storable]
|
---|
28 | public DateTime dateTime = new DateTime();
|
---|
29 | [Storable]
|
---|
30 | public KeyValuePair<string, int> kvp = new KeyValuePair<string, int>("test key", 123);
|
---|
31 | [Storable]
|
---|
32 | public Dictionary<string, int> dict = new Dictionary<string, int>();
|
---|
33 | }
|
---|
34 |
|
---|
35 | public class Custom {
|
---|
36 | [Storable]
|
---|
37 | public int i;
|
---|
38 | [Storable]
|
---|
39 | public Root r;
|
---|
40 | [Storable]
|
---|
41 | public string name = "Serial";
|
---|
42 | }
|
---|
43 |
|
---|
44 | public class NewSerializationTest {
|
---|
45 | public static void Main() {
|
---|
46 | Root r = new Root();
|
---|
47 | r.selfReferences = new List<Root>();
|
---|
48 | r.selfReferences.Add(r);
|
---|
49 | r.selfReferences.Add(r);
|
---|
50 | r.c = new Custom();
|
---|
51 | r.c.r = r;
|
---|
52 | r.dict.Add("one", 1);
|
---|
53 | r.dict.Add("two", 2);
|
---|
54 | r.dict.Add("three", 3);
|
---|
55 | Serializer s = new Serializer(r);
|
---|
56 | Persistence.XmlFormatter xmlFormatter = new Persistence.XmlFormatter();
|
---|
57 | StreamWriter writer = new StreamWriter("test.xml");
|
---|
58 | foreach (ISerializationToken token in s) {
|
---|
59 | string line = xmlFormatter.Format(token);
|
---|
60 | writer.Write(line);
|
---|
61 | Console.Out.Write(line);
|
---|
62 | }
|
---|
63 | writer.Close();
|
---|
64 | XmlParser parser = new XmlParser(new StreamReader("test.xml"));
|
---|
65 | DeSerializer deSerializer = new DeSerializer();
|
---|
66 | object o = deSerializer.DeSerialize(parser);
|
---|
67 | Console.Out.WriteLine(Util.AutoFormat(o, true));
|
---|
68 | Console.In.ReadLine();
|
---|
69 | }
|
---|
70 | }
|
---|
71 | }
|
---|