System.IO.FileStream.PrepareForWriting C# (CSharp) Method

PrepareForWriting() private method

Validates that we're ready to write to the stream, including flushing a read buffer if necessary.
private PrepareForWriting ( ) : void
return void
        private void PrepareForWriting()
        {
            if (_fileHandle.IsClosed)
                throw Error.GetFileNotOpen();

            // Make sure we're good to write.  We only need to do this if there's nothing already
            // in our write buffer, since if there is something in the buffer, we've already done 
            // this checking and flushing.
            if (_writePos == 0)
            {
                if (!CanWrite) throw Error.GetWriteNotSupported();
                FlushReadBuffer();
                Debug.Assert(_bufferLength > 0, "_bufferSize > 0");
            }
        }