Sha256: b31b18414fcc54114e8db18856da904ea1b88b66da693dc7538a3447c7710b5d
Contents?: true
Size: 1.21 KB
Versions: 2
Compression:
Stored size: 1.21 KB
Contents
using System; using System.Collections.Generic; namespace ClrModels { public class ExplodingCar { public virtual event EventHandler<EventArgs> OnExploded; public void Explode(){ // do logic here to make car explode TriggerOnExploded(); } protected virtual void TriggerOnExploded(){ var handler = OnExploded; if(handler != null){ handler.Invoke(this, EventArgs.Empty); } } } public class CleanupCrew : IDisposable{ private bool _isDisposed = false; private ExplodingCar _car; public CleanupCrew(ExplodingCar car){ _car = car; //don't use anonymous delegates or lambda's _car.OnExploded += Handle_carOnExploded; } void Handle_carOnExploded (object sender, EventArgs e) { // Do logic here when car exploded. Clean street, repair buildings etc. } public void Dispose(){ Dispose(true); // Keep this here for subclasses that may use unmanaged resources GC.SuppressFinalize(this); } protected virtual void Dispose(bool isDisposing){ if(!_isDisposed){ if(isDisposing){ // detach event handlers here etc. _car.OnExploded -= Handle_carOnExploded; } _isDisposed = true; // unmanaged resources here. } } } }
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
caricature-0.7.7 | spec/fixtures/ExplodingCar.cs |
caricature-0.7.6 | spec/fixtures/ExplodingCar.cs |