Exemplo n.º 1
0
        public static void RunTest()
        {
            TreeTest input  = new TreeTest(43);
            TreeTest common = new TreeTest(66);

            common.other.Add(new TreeTest(100));
            input.other.Add(common);
            input.other.Add(common);
            input.other.Add(common);

            MemoryStream     ms = new MemoryStream();
            BinaryWriter     bw = new BinaryWriter(ms);
            SerializeContext serializeContext = new SerializeContext(bw);

            Field.Serialize(serializeContext, bw, ref input);


            BinaryReader       br = new BinaryReader(new MemoryStream(ms.ToArray()));
            DeserializeContext deserializeContext = new DeserializeContext(br);

            TreeTest result = null;

            Field.Deserialize(deserializeContext, br, ref result);

            Debug.Assert(input.Equals(result));
            foreach (var item in result.other)
            {
                // Check the graph works:
                Debug.Assert(ReferenceEquals(item, result.other[0]));
            }
        }
Exemplo n.º 2
0
        public static void RunTestWithDefinitions()
        {
            TreeTest definition  = new TreeTest(66);
            TreeTest definition2 = new TreeTest(100);

            definition.other.Add(definition2);

            TreeTest input = new TreeTest(43);

            input.other.Add(definition);
            input.other.Add(definition);
            input.other.Add(definition);

            var definitionTable = GetDefinitionTable(definition);

            MemoryStream     ms = new MemoryStream();
            BinaryWriter     bw = new BinaryWriter(ms);
            SerializeContext serializeContext = new SerializeContext(bw, false, definitionTable);

            Field.Serialize(serializeContext, bw, ref input);


            BinaryReader       br = new BinaryReader(new MemoryStream(ms.ToArray()));
            DeserializeContext deserializeContext = new DeserializeContext(br, definitionTable);

            TreeTest result = null;

            Field.Deserialize(deserializeContext, br, ref result);


            Debug.Assert(input.Equals(result));
            foreach (var item in result.other)
            {
                // Check that we refer back to definition objects
                Debug.Assert(ReferenceEquals(item, definition));
            }
            Debug.Assert(ReferenceEquals(definition.other[0], definition2));
        }