示例#1
0
        public void CanSerializeCyclicReferences()
        {
            var stream = new MemoryStream();
            var serializer = new Serializer(new SerializerOptions(preserveObjectReferences: true,versionTolerance:true));
            var bar = new Bar();
            bar.Self = bar;
            bar.XYZ = 234;

            serializer.Serialize(bar, stream);
            stream.Position = 0;
            var actual = serializer.Deserialize<Bar>(stream);
            Assert.Same(actual, actual.Self);
            Assert.Equal(bar.XYZ, actual.XYZ);
        }
示例#2
0
        public void CanSerializeDeepCyclicReferences()
        {
            var stream = new MemoryStream();
            var serializer = new Serializer(new SerializerOptions(preserveObjectReferences: true,versionTolerance:true));
            var root = new Root();
            var bar = new Bar();
            bar.Self = bar;
            bar.XYZ = 234;
            root.B1 = bar;
            root.B2 = bar;

            serializer.Serialize(root, stream);
            stream.Position = 0;
            var actual = serializer.Deserialize<Root>(stream);
            Assert.Same(actual.B1, actual.B1);
            Assert.Same(actual.B1, actual.B2);
            Assert.Same(actual.B1, actual.B1.Self);
            Assert.Same(actual.B1, actual.B2.Self);
        }