Free cookie consent management tool by TermsFeed Policy Generator

source: branches/New Persistence Exploration/Persistence/Persistence/NewSerializationTest.cs @ 1281

Last change on this file since 1281 was 1281, checked in by epitzer, 15 years ago

Proper deserialization of parent references. (#506)

File size: 1.9 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Collections;
5using System.IO;
6
7namespace 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
26  public class Custom {
27    [Storable]
28    public int i;
29    [Storable]
30    public Root r;
31    [Storable]
32    public string name = "Serial";
33  }
34
35  public class NewSerializationTest {
36    public static void Main() {
37      Root r = new Root();
38      r.selfReferences = new List<Root>();
39      r.selfReferences.Add(r);
40      r.selfReferences.Add(r);
41      r.c = new Custom();
42      r.c.r = r;
43      IPrimitiveSerializer[] serializers = {
44          new String2XMLSerializer(),
45          new Int2XMLSerializer()};
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[] { new Int2XMLSerializer(), new String2XMLSerializer() },
58        new ICustomSerializer[] { new ArraySerializer(), new EnumerableSerializer() });
59      object o = deSerializer.DeSerialize(parser);
60      Console.Out.WriteLine(Util.AutoFormat(o, true));
61      Console.In.ReadLine();
62    }
63  }
64}
Note: See TracBrowser for help on using the repository browser.