// This method demonstrates how the GC works. private static void Introduction() { Display(0, "\n\nDemo start: Introduction to Garbage Collection.", +1); // Create a new DerivedObj in the managed heap // Note: Both BaseObj and DerivedObj constructors are called DerivedObj obj = new DerivedObj("Introduction"); obj = null; // We no longer need this object // The object is unreachable so forcing a GC causes it to be finalized. Collect(); // Wait for the GC's Finalize thread to finish // executing all queued Finalize methods. WaitForFinalizers(); // NOTE: The GC calls the most-derived (farthest away from // the Object base class) Finalize only. // Base class Finalize functions are called only if the most-derived // Finalize method explicitly calls its base class's Finalize method. // This is the same test as above with one slight variation obj = new DerivedObj("Introduction"); // obj = null; // Variation: this line is commented out Collect(); WaitForFinalizers(); // Notice that we get identical results as above: the Finalize method // runs because the jitter's optimizer knows that obj is not // referenced later in this function. Display(-1, "Demo stop: Introduction to Garbage Collection.", 0); }
protected override void setupExpectations() { _data = new DerivedObj(); _objectSubscriber.Expect(s => s.OnPublished(_data)); _baseObjSubscriber.Expect(s => s.OnPublished(_data)); _derivedObjSubscriber.Expect(s => s.OnPublished(_data)); }
protected override void setupExpectations() { _data = new DerivedObj(); _event = new Event<BaseObj>(_data); _objectSubscriber.Expect(s => s.OnPublished(_event)); _eventWithObjectSubscriber.Expect(s => s.OnPublished(null)) .Constraints(Property.Value("Data", _data)) .Message("_eventWithObjectSubscriber"); _eventWithBaseObjSubscriber.Expect(s => s.OnPublished(null)) .Constraints(Property.Value("Data", _data)) .Message("_eventWithBaseObjSubscriber"); }
public void SerializeDeserialize_ShouldPreserveValues() { var obj = new DerivedObj() { Length = 123.1, Name = "Lol123!", Lives = 7, Strength = 4.8 }; string str = BasicSerializer.Serialize(obj); BaseObj mirrorBase = BasicSerializer.Deserialize <BaseObj>(str); DerivedObj mirror = Assert.IsType <DerivedObj>(mirrorBase); Assert.Equal(obj.Length, mirror.Length); Assert.Equal(obj.Name, mirror.Name); Assert.Equal(obj.Lives, mirror.Lives); Assert.Equal(obj.Strength, mirror.Strength); }