public AbstractState DoTransition(string stateToTransitionTo) { String stateValueKey = stateToTransitionTo.ToLower(); if (!AbstractState.valuesToStates.ContainsKey(stateValueKey)) { throw new Exception(String.Format("{0} does not exist", stateValueKey)); } AbstractState stateToCheckFor = AbstractState.valuesToStates[stateValueKey]; if (AbstractState.allowedTransitions.Exists(item => item.GetHashCode() == stateToCheckFor.GetHashCode())) { AbstractState.allowedTransitions.Remove(stateToCheckFor); return(stateToCheckFor); } else { return(null); } }