/// <summary> /// Add a new state transition to the state machine. /// </summary> /// <param name="initialState">Beginning state of transition.</param> /// <param name="endState">Ending state of transition.</param> /// <param name="action">Callback action method to execute after transition.</param> public void AddTransition(E initialState, E endState, Action action) { StateTransition <E> transition = new StateTransition <E>(initialState, endState); // Check if transition already exists. if (this.stateTransitions.ContainsKey(transition)) { // Transtion already exists. return; } // Add transition. this.stateTransitions.Add(transition, action); }
/// <summary> /// Check if this StateTransition is the same as another. /// </summary> /// <param name="stateTransition">StateTransition to check against.</param> /// <returns>true if StateTransitions are the same.</returns> public bool Equals(StateTransition <E> stateTransition) { if (ReferenceEquals(stateTransition, this)) { return(true); } else if (ReferenceEquals(stateTransition, null)) { throw new ArgumentNullException("stateTransition argument must not be null."); } else { bool isEqual = this.initialState.Equals(stateTransition.InitialState) && this.endState.Equals(stateTransition.EndState); return(isEqual); } }