public void CanCloneCycleUsingSerialization() { this.prototypeUsingSerialization.ReferenceObject.Dynamic = this.prototypeUsingSerialization; PrototypeUsingSerialization cloned = this.prototypeUsingSerialization.DeepClone(); Assert.AreSame(cloned, cloned.ReferenceObject.Dynamic); }
public void TestPrototypeUsingSerialization() { PrototypeUsingSerialization cloned = this.prototypeUsingSerialization.DeepClone(); Assert.AreEqual(cloned.Number, this.prototypeUsingSerialization.Number); Assert.AreNotSame(cloned.Number, this.prototypeUsingSerialization.Number); Assert.AreEqual(cloned.Text, this.prototypeUsingSerialization.Text); Assert.AreNotSame(cloned.Text, this.prototypeUsingSerialization.Text); Assert.AreEqual(cloned.ReferenceObject.Text, this.prototypeUsingSerialization.ReferenceObject.Text); Assert.AreNotSame(cloned.ReferenceObject, this.prototypeUsingSerialization.ReferenceObject); Assert.AreNotSame(cloned.Collection, this.prototypeUsingSerialization.Collection); Assert.AreEqual(cloned.Collection[0].Text, this.prototypeUsingSerialization.Collection[0].Text); Assert.AreNotSame(cloned.Collection[0], this.prototypeUsingSerialization.Collection[0]); }
private static void Main(string[] args) { SetUp(); var stopwatch = new Stopwatch(); // ====== PrototypeUsingSerialization ====== stopwatch.Start(); PrototypeUsingSerialization prototypeUsingSerializationClone = null; for (int i = 0; i < 10_000; i++) { prototypeUsingSerializationClone = prototypeUsingSerialization.DeepClone(); } stopwatch.Stop(); Console.WriteLine($"Number of ticks for {nameof(PrototypeUsingSerialization)}: {stopwatch.ElapsedTicks}"); stopwatch.Reset(); // ====== PrototypeUsingReflection ========= stopwatch.Start(); PrototypeUsingReflection prototypeUsingReflectionClone = null; for (int i = 0; i < 10_000; i++) { prototypeUsingReflectionClone = prototypeUsingReflection.DeepClone(); } stopwatch.Stop(); Console.WriteLine($"Number of ticks for {nameof(PrototypeUsingReflection)}: {stopwatch.ElapsedTicks}"); stopwatch.Reset(); Console.ReadKey(); }
private static void SetUp() { prototypeUsingSerialization = new PrototypeUsingSerialization { Number = 99, Text = "Test String", ReferenceObject = new ReferenceObject { Text = "Some Text" }, Collection = new List <ReferenceObject> { new ReferenceObject { Text = "1" }, new ReferenceObject { Text = "2" } } }; prototypeUsingReflection = new PrototypeUsingReflection { Number = 99, Text = "Test String", ReferenceObject = new ReferenceObject { Text = "Some Text" }, Collection = new List <ReferenceObject> { new ReferenceObject { Text = "1" }, new ReferenceObject { Text = "2" } } }; }