public SerializationEventsClass AddChild(string name) { SerializationEventsClass child = new SerializationEventsClass { Name = name }; children.Add(child); child.parent = this; privatePointer = new IntPtr(children.Count); return child; }
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); }