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 | }
|
---|
24 |
|
---|
25 | public class Custom {
|
---|
26 | [Storable]
|
---|
27 | public int i;
|
---|
28 | [Storable]
|
---|
29 | public Root r;
|
---|
30 | [Storable]
|
---|
31 | public string name = "Serial";
|
---|
32 | }
|
---|
33 |
|
---|
34 | public class NewSerializationTest {
|
---|
35 | public static void Main() {
|
---|
36 | Root r = new Root();
|
---|
37 | r.selfReferences = new List<Root>();
|
---|
38 | r.selfReferences.Add(r);
|
---|
39 | r.selfReferences.Add(r);
|
---|
40 | r.c = new Custom();
|
---|
41 | r.c.r = r;
|
---|
42 | IPrimitiveSerializer[] serializers = {
|
---|
43 | new String2XMLSerializer(),
|
---|
44 | new Int2XMLSerializer(),
|
---|
45 | new Double2XmlSerializer()};
|
---|
46 | Serializer s = new Serializer(r, serializers);
|
---|
47 | Persistence.XmlFormatter xmlFormatter = new Persistence.XmlFormatter();
|
---|
48 | StreamWriter writer = new StreamWriter("test.xml");
|
---|
49 | foreach (ISerializationToken token in s) {
|
---|
50 | string line = xmlFormatter.Format(token);
|
---|
51 | writer.Write(line);
|
---|
52 | Console.Out.Write(line);
|
---|
53 | }
|
---|
54 | writer.Close();
|
---|
55 | XmlParser parser = new XmlParser(new StreamReader("test.xml"));
|
---|
56 | DeSerializer deSerializer = new DeSerializer(
|
---|
57 | new IPrimitiveSerializer[] {
|
---|
58 | new Int2XMLSerializer(),
|
---|
59 | new String2XMLSerializer(),
|
---|
60 | new Double2XmlSerializer(),
|
---|
61 | },
|
---|
62 | new ICompoundSerializer[] {
|
---|
63 | new ArraySerializer(),
|
---|
64 | new EnumerableSerializer() });
|
---|
65 | object o = deSerializer.DeSerialize(parser);
|
---|
66 | Console.Out.WriteLine(Util.AutoFormat(o, true));
|
---|
67 | Console.In.ReadLine();
|
---|
68 | }
|
---|
69 | }
|
---|
70 | }
|
---|