public void RequestState(SqlWriterState state) { if (IsClosed) { throw new InvalidOperationException("The writer has already been closed."); } // Build in a safety net for missing state transitions. SqlWriterState[] validNextStates; if (!_transitions.TryGetValue(CurrentState, out validNextStates)) { throw new InvalidOperationException( string.Format( "The current state '{0}' does not allow any state transitions. " + "This error should not occur, please report this to the authors of this library.", CurrentState)); } // Provide enough information to try and guess what's wrong. if (!validNextStates.Contains(state)) { throw new InvalidOperationException( string.Format( "The current state '{0}' is invalid for the requested state '{1}'. Valid next states are '{2}'.", CurrentState, state, string.Join("', '", validNextStates))); } _states.Push(state); }
public void RequestState(SqlWriterState state) { if (IsClosed) throw new InvalidOperationException("The writer has already been closed."); // Build in a safety net for missing state transitions. SqlWriterState[] validNextStates; if (!_transitions.TryGetValue(CurrentState, out validNextStates)) throw new InvalidOperationException( string.Format( "The current state '{0}' does not allow any state transitions. " + "This error should not occur, please report this to the authors of this library.", CurrentState)); // Provide enough information to try and guess what's wrong. if (!validNextStates.Contains(state)) throw new InvalidOperationException( string.Format( "The current state '{0}' is invalid for the requested state '{1}'. Valid next states are '{2}'.", CurrentState, state, string.Join("', '", validNextStates))); _states.Push(state); }