System.Data.DataTableReader.GetChars C# (CSharp) Method

GetChars() public method

public GetChars ( int ordinal, long dataIndex, char buffer, int bufferIndex, int length ) : long
ordinal int
dataIndex long
buffer char
bufferIndex int
length int
return long
        public override long GetChars(int ordinal, long dataIndex, char[] buffer, int bufferIndex, int length)
        {
            ValidateState(nameof(GetChars));
            ValidateReader();
            char[] tempBuffer;
            try
            {
                tempBuffer = (char[])_currentDataRow[ordinal];
            }
            catch (IndexOutOfRangeException e)
            {
                // thrown by DataColumnCollection
                ExceptionBuilder.TraceExceptionWithoutRethrow(e);
                throw ExceptionBuilder.ArgumentOutOfRange(nameof(ordinal));
            }

            if (buffer == null)
            {
                return tempBuffer.Length;
            }

            int srcIndex = (int)dataIndex;
            int charCount = Math.Min(tempBuffer.Length - srcIndex, length);
            if (srcIndex < 0)
            {
                throw ADP.InvalidSourceBufferIndex(tempBuffer.Length, srcIndex, nameof(dataIndex));
            }
            else if ((bufferIndex < 0) || (bufferIndex > 0 && bufferIndex >= buffer.Length))
            {
                throw ADP.InvalidDestinationBufferIndex(buffer.Length, bufferIndex, nameof(bufferIndex));
            }

            if (0 < charCount)
            {
                Array.Copy(tempBuffer, dataIndex, buffer, bufferIndex, charCount);
            }
            else if (length < 0)
            {
                throw ADP.InvalidDataLength(length);
            }
            else
            {
                charCount = 0;
            }
            return charCount;
        }