private void AssertSequentialAccess(int ordinal, long dataOffset, string methodName) { if (ordinal < 0 || ordinal >= this._source.ColumnCount) { throw new ArgumentOutOfRangeException(nameof(ordinal)); } if (this._lastColumnRead > ordinal || this._lastColumnRead == ordinal && this._lastDataOffsetRead == long.MaxValue) { throw new InvalidOperationException(Strings.ADP_NonSequentialColumnAccess((object)ordinal.ToString((IFormatProvider)CultureInfo.InvariantCulture), (object)(this._lastColumnRead + 1).ToString((IFormatProvider)CultureInfo.InvariantCulture))); } if (this._lastColumnRead == ordinal) { if (this._lastDataOffsetRead >= dataOffset) { throw new InvalidOperationException(Strings.ADP_NonSequentialChunkAccess((object)dataOffset.ToString((IFormatProvider)CultureInfo.InvariantCulture), (object)(this._lastDataOffsetRead + 1L).ToString((IFormatProvider)CultureInfo.InvariantCulture), (object)methodName)); } } else { this._lastColumnRead = ordinal; this._lastDataOffsetRead = -1L; } }
/// <summary> /// Ensures that sequential access rules are being obeyed for array offset /// getter methods, throws the appropriate exception if not. Also ensures /// that the last column and array offset is set appropriately. /// </summary> /// <param name="ordinal"> </param> /// <param name="dataOffset"> </param> /// <param name="methodName"> </param> private void AssertSequentialAccess(int ordinal, long dataOffset, string methodName) { Debug.Assert(null != _source, "null _source?"); // we should have already called AssertReaderIsOpen. if (ordinal < 0 || ordinal >= _source.ColumnCount) { throw new ArgumentOutOfRangeException("ordinal"); } if (_lastColumnRead > ordinal || (_lastColumnRead == ordinal && _lastDataOffsetRead == long.MaxValue)) { throw new InvalidOperationException( Strings.ADP_NonSequentialColumnAccess( ordinal.ToString(CultureInfo.InvariantCulture), (_lastColumnRead + 1).ToString(CultureInfo.InvariantCulture))); } if (_lastColumnRead == ordinal) { if (_lastDataOffsetRead >= dataOffset) { throw new InvalidOperationException( Strings.ADP_NonSequentialChunkAccess( dataOffset.ToString(CultureInfo.InvariantCulture), (_lastDataOffsetRead + 1).ToString(CultureInfo.InvariantCulture), methodName)); } // _lastDataOffsetRead will be set by GetBytes/GetChars, since we need to set it // to the last offset that was actually read, which isn't necessarily what was // requested. } else { // Doin' a new thang... _lastColumnRead = ordinal; _lastDataOffsetRead = -1; } }