public void ClearNotRequired() { // test various classes for which Clear() is a no-op var s1 = new STStructSimple(100); var s2 = new STStructSimple(100); Assert.IsTrue(s1.Equals(s2)); Serializer.Clear(ref s1, new SerializationContext()); Assert.IsTrue(s1.Equals(s2)); var c1 = new STClass(FooEnum.One, 1, "one", new[] { 1.0 }); var c2 = new STClass(FooEnum.One, 1, "one", new[] { 1.0 }); Assert.IsTrue(c1.Same(c2)); Serializer.Clear(ref c1, new SerializationContext()); Assert.IsTrue(c1.Same(c2)); var sc1 = new STStructComplex(100); var sc2 = new STStructComplex(100); Assert.IsTrue(sc1.Same(sc2)); Serializer.Clear(ref sc1, new SerializationContext()); Assert.IsTrue(sc1.Same(sc2)); var arr = new STStructComplex[1]; arr[0] = sc1; Assert.IsTrue(sc1.Same(sc2)); Serializer.Clear(ref arr, new SerializationContext()); Assert.IsTrue(sc1.Same(sc2)); var list = new List <STStructComplex>(); list.Add(sc1); Assert.IsTrue(sc1.Same(sc2)); Serializer.Clear(ref list, new SerializationContext()); Assert.IsTrue(sc1.Same(sc2)); var dict = new Dictionary <int, STStructComplex>(); dict.Add(1, sc1); Assert.IsTrue(sc1.Same(sc2)); Serializer.Clear(ref dict, new SerializationContext()); Assert.IsTrue(sc1.Same(sc2)); }
public void ReceiveClassByRef() { var c = new STClass(); STClass result = null; using (var p = Pipeline.Create("ReceiveClassByRef", DeliveryPolicy.Unlimited, allowSchedulingOnExternalThreads: true)) { var receiver = p.CreateReceiver<STClass>( this, msg => { result = msg.Data; }, "receiver"); Generators.Return(p, c).PipeTo(receiver, Immediate); p.Run(); } Assert.IsTrue(result.Same(c)); Assert.AreEqual(result, c); // we expect the same instance }
public void ReceiveClassByValue() { var c = new STClass(); STClass result = null; using (var p = Pipeline.Create()) { var receiver = p.CreateReceiver<STClass>( this, msg => { result = msg.Data; }, "receiver"); Generators.Return(p, c).PipeTo(receiver, DeliveryPolicy.Unlimited); p.Run(); } Assert.IsTrue(result.Same(c)); Assert.AreNotEqual(result, c); // we expect a different instance }
public void ReceiveClassByRef() { var c = new STClass(); STClass result = null; using (var p = Pipeline.Create("ReceiveClassByRef", DeliveryPolicy.Unlimited, allowSchedulingOnExternalThreads: true)) { var emitter = p.CreateEmitter <STClass>(this, "emitter"); var receiver = p.CreateReceiver <STClass>( this, msg => { result = msg.Data; }, "receiver"); emitter.PipeTo(receiver, immediate); p.RunAsync(); emitter.Post(c, DateTime.MinValue); } Assert.IsTrue(result.Same(c)); Assert.AreEqual(result, c); // we expect the same instance }
public void ReceiveClassByValue() { var c = new STClass(); STClass result = null; using (var p = Pipeline.Create()) { var emitter = p.CreateEmitter <STClass>(this, "emitter"); var receiver = p.CreateReceiver <STClass>( this, msg => { result = msg.Data; }, "receiver"); emitter.PipeTo(receiver, DeliveryPolicy.Unlimited); p.RunAsync(); emitter.Post(c, DateTime.MinValue); } Assert.IsTrue(result.Same(c)); Assert.AreNotEqual(result, c); // we expect a different instance }