System.Data.SqlTypes.SqlStreamChars.Write C# (CSharp) Method

Write() public abstract method

public abstract Write ( char buffer, int offset, int count ) : void
buffer char
offset int
count int
return void
        public abstract void Write(char[] buffer, int offset, int count);

Usage Example

Example #1
0
        // Write data of specified length into the SqlChars from specified offset

        public void Write(long offset, char[] buffer, int offsetInBuffer, int count)
        {
            if (FStream())
            {
                if (m_stream.Position != offset)
                {
                    m_stream.Seek(offset, SeekOrigin.Begin);
                }
                m_stream.Write(buffer, offsetInBuffer, count);
            }
            else
            {
                // Validate the arguments
                if (buffer == null)
                {
                    throw new ArgumentNullException("buffer");
                }

                if (m_rgchBuf == null)
                {
                    throw new SqlTypeException(Res.GetString(Res.SqlMisc_NoBufferMessage));
                }

                if (offset < 0)
                {
                    throw new ArgumentOutOfRangeException("offset");
                }
                if (offset > m_rgchBuf.Length)
                {
                    throw new SqlTypeException(Res.GetString(Res.SqlMisc_BufferInsufficientMessage));
                }

                if (offsetInBuffer < 0 || offsetInBuffer > buffer.Length)
                {
                    throw new ArgumentOutOfRangeException("offsetInBuffer");
                }

                if (count < 0 || count > buffer.Length - offsetInBuffer)
                {
                    throw new ArgumentOutOfRangeException("count");
                }

                if (count > m_rgchBuf.Length - offset)
                {
                    throw new SqlTypeException(Res.GetString(Res.SqlMisc_BufferInsufficientMessage));
                }

                if (IsNull)
                {
                    // If NULL and there is buffer inside, we only allow writing from
                    // offset zero.
                    //
                    if (offset != 0)
                    {
                        throw new SqlTypeException(Res.GetString(Res.SqlMisc_WriteNonZeroOffsetOnNullMessage));
                    }

                    // treat as if our current length is zero.
                    // Note this has to be done after all inputs are validated, so that
                    // we won't throw exception after this point.
                    //
                    _lCurLen = 0;
                    _state   = SqlBytesCharsState.Buffer;
                }
                else if (offset > _lCurLen)
                {
                    // Don't allow writing from an offset that this larger than current length.
                    // It would leave uninitialized data in the buffer.
                    //
                    throw new SqlTypeException(Res.GetString(Res.SqlMisc_WriteOffsetLargerThanLenMessage));
                }

                if (count != 0)
                {
                    // ProjectK\Core doesn't support long-typed array indexers
                    Debug.Assert(offset < int.MaxValue);
                    Array.Copy(buffer, offsetInBuffer, m_rgchBuf, checked ((int)offset), count);

                    // If the last position that has been written is after
                    // the current data length, reset the length
                    if (_lCurLen < offset + count)
                    {
                        _lCurLen = offset + count;
                    }
                }
            }

            AssertValid();
        }