예제 #1
0
 public SerializationEventsClass AddChild(string name)
 {
     SerializationEventsClass child = new SerializationEventsClass { Name = name };
     children.Add(child);
     child.parent = this;
     privatePointer = new IntPtr(children.Count);
     return child;
 }
예제 #2
0
        public void IgnoreNonSerializedAttributeTest()
        {
            object obj = new SerializationEventsClass { Name = "Parent" }.AddChild("Child").Parent;
            var surrogate = new CustomSerializerSurrogateSelector();

            // Formatter now omits serialization methods. If the surrogate selector skips non-serialized fields, it will cause a problem.
            var formatter = new BinarySerializationFormatter(BinarySerializationOptions.IgnoreSerializationMethods) { SurrogateSelector = surrogate };
            Throws<AssertionException>(() => DoTest(formatter, surrogate, obj, true, true, true),
                "Equality check failed");

            // But if we force to serialize all fields, even non-serialized ones, the clones will be identical.
            surrogate.IgnoreNonSerializedAttribute = true;
            DoTest(formatter, surrogate, obj, true, true, true);
        }