using System; namespace Chernobyl.Switch { /// /// A switch that requires two events to be received in order before the /// switches output event is raised. In other words, when /// and THEN is invoked, will /// be invoked. If is invoked before , /// will NOT fire. /// public class OneTwoSwitch : ISwitch { /// /// Constructor. /// public OneTwoSwitch() {} /// /// Constructor. /// /// Methods to assign to the event /// . public OneTwoSwitch(params EventHandler[] onSwitchHandlers) { foreach (EventHandler eh in onSwitchHandlers) SwitchedOn += eh; } /// /// An event that is raised when the method and /// THEN is invoked. If the methods are invoked /// the other way around, the event will not be invoked. /// public event EventHandler SwitchedOn; /// /// An event that is raised right after this switch has been switched /// off (or reset). /// public event EventHandler SwitchedOff; /// /// An event handler that can be assigned to an event. This method must /// be invoked before is invoked for the event /// to be invoked. /// /// The sender of the event. /// The events arguments. public void Switch1(object sender, EventArgs e) { Switch1Value = true; } /// /// An event handler that can be assigned to an event. This method must /// be invoked after is invoked for the event /// to be invoked. /// /// The sender of the event. /// The events arguments. public void Switch2(object sender, EventArgs e) { if (Switch1Value == true && SwitchedOn != null) SwitchedOn(this, EventArgs.Empty); } /// /// Overrides . /// public void Reset() { Switch1Value = false; if (SwitchedOff != null) SwitchedOff(this, EventArgs.Empty); } /// /// Overrides . /// public void Reset(object sender, EventArgs e) { Reset(); } /// /// True if has been invoked, false if otherwise. /// bool Switch1Value; } }