Exemple #1
0
        public override long GetChars(int ordinal, long dataIndex, char[] buffer, int bufferIndex, int length)
        {
            char[] tempBuffer;
            tempBuffer = (char[])GetValue(ordinal);

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

            var srcIndex  = (int)dataIndex;
            var charCount = Math.Min(tempBuffer.Length - srcIndex, length);

            if (srcIndex < 0)
            {
                throw new ArgumentOutOfRangeException(
                          "bufferIndex", Strings.ADP_InvalidSourceBufferIndex(
                              buffer.Length.ToString(CultureInfo.InvariantCulture), ((long)bufferIndex).ToString(CultureInfo.InvariantCulture)));
            }
            else if ((bufferIndex < 0) ||
                     (bufferIndex > 0 && bufferIndex >= buffer.Length))
            {
                throw new ArgumentOutOfRangeException(
                          "bufferIndex", Strings.ADP_InvalidDestinationBufferIndex(
                              buffer.Length.ToString(CultureInfo.InvariantCulture), bufferIndex.ToString(CultureInfo.InvariantCulture)));
            }

            if (0 < charCount)
            {
                Array.Copy(tempBuffer, dataIndex, buffer, bufferIndex, charCount);
            }
            else if (length < 0)
            {
                throw new IndexOutOfRangeException(Strings.ADP_InvalidDataLength(((long)length).ToString(CultureInfo.InvariantCulture)));
            }
            else
            {
                charCount = 0;
            }
            return(charCount);
        }
Exemple #2
0
        public override long GetBytes(
            int i,
            long dataIndex,
            byte[] buffer,
            int bufferIndex,
            int length)
        {
            byte[] numArray = (byte[])this.GetValue(i);
            if (buffer == null)
            {
                return((long)numArray.Length);
            }
            int num1 = (int)dataIndex;
            int num2 = Math.Min(numArray.Length - num1, length);

            if (num1 < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(dataIndex), Strings.ADP_InvalidSourceBufferIndex((object)numArray.Length.ToString((IFormatProvider)CultureInfo.InvariantCulture), (object)((long)num1).ToString((IFormatProvider)CultureInfo.InvariantCulture)));
            }
            if (bufferIndex < 0 || bufferIndex > 0 && bufferIndex >= buffer.Length)
            {
                throw new ArgumentOutOfRangeException(nameof(bufferIndex), Strings.ADP_InvalidDestinationBufferIndex((object)buffer.Length.ToString((IFormatProvider)CultureInfo.InvariantCulture), (object)bufferIndex.ToString((IFormatProvider)CultureInfo.InvariantCulture)));
            }
            if (0 < num2)
            {
                Array.Copy((Array)numArray, dataIndex, (Array)buffer, (long)bufferIndex, (long)num2);
            }
            else
            {
                if (length < 0)
                {
                    throw new IndexOutOfRangeException(Strings.ADP_InvalidDataLength((object)((long)length).ToString((IFormatProvider)CultureInfo.InvariantCulture)));
                }
                num2 = 0;
            }
            return((long)num2);
        }
        public override long GetChars(int ordinal, long fieldOffset, char[] buffer, int bufferOffset, int length)
        {
            var cchars = 0;
            int ndataIndex;
            var data = (string)_values[ordinal];

            cchars = data.Length;

            // since arrays can't handle 64 bit values and this interface doesn't
            // allow chunked access to data, a dataIndex outside the rang of Int32
            // is invalid
            if (fieldOffset > Int32.MaxValue)
            {
                throw new ArgumentOutOfRangeException(
                          "fieldOffset", Strings.ADP_InvalidSourceBufferIndex(
                              cchars.ToString(CultureInfo.InvariantCulture), fieldOffset.ToString(CultureInfo.InvariantCulture)));
            }

            ndataIndex = (int)fieldOffset;

            // if no buffer is passed in, return the number of characters we have
            if (null == buffer)
            {
                return(cchars);
            }

            try
            {
                if (ndataIndex < cchars)
                {
                    // help the user out in the case where there's less data than requested
                    if ((ndataIndex + length) > cchars)
                    {
                        cchars = cchars - ndataIndex;
                    }
                    else
                    {
                        cchars = length;
                    }
                }
                data.CopyTo(ndataIndex, buffer, bufferOffset, cchars);
            }
            catch (Exception e)
            {
                if (e.IsCatchableExceptionType())
                {
                    cchars = data.Length;

                    if (length < 0)
                    {
                        throw new IndexOutOfRangeException(
                                  Strings.ADP_InvalidDataLength(((long)length).ToString(CultureInfo.InvariantCulture)));
                    }

                    // if bad buffer index, throw
                    if (bufferOffset < 0 ||
                        bufferOffset >= buffer.Length)
                    {
                        throw new ArgumentOutOfRangeException(
                                  "bufferOffset", Strings.ADP_InvalidDestinationBufferIndex(
                                      buffer.Length.ToString(CultureInfo.InvariantCulture), bufferOffset.ToString(CultureInfo.InvariantCulture)));
                    }

                    // if bad data index, throw
                    if (fieldOffset < 0 ||
                        fieldOffset >= cchars)
                    {
                        throw new ArgumentOutOfRangeException(
                                  "fieldOffset", Strings.ADP_InvalidSourceBufferIndex(
                                      cchars.ToString(CultureInfo.InvariantCulture), fieldOffset.ToString(CultureInfo.InvariantCulture)));
                    }

                    // if there is not enough room in the buffer for data
                    if (cchars + bufferOffset
                        > buffer.Length)
                    {
                        throw new IndexOutOfRangeException(
                                  Strings.ADP_InvalidBufferSizeOrIndex(
                                      cchars.ToString(CultureInfo.InvariantCulture), bufferOffset.ToString(CultureInfo.InvariantCulture)));
                    }
                }

                throw;
            }

            return(cchars);
        }
Exemple #4
0
        public override long GetBytes(
            int ordinal,
            long fieldOffset,
            byte[] buffer,
            int bufferOffset,
            int length)
        {
            byte[] numArray = (byte[])this._values[ordinal];
            int    length1  = numArray.Length;

            if (fieldOffset > (long)int.MaxValue)
            {
                throw new ArgumentOutOfRangeException(nameof(fieldOffset), Strings.ADP_InvalidSourceBufferIndex((object)length1.ToString((IFormatProvider)CultureInfo.InvariantCulture), (object)fieldOffset.ToString((IFormatProvider)CultureInfo.InvariantCulture)));
            }
            int sourceIndex = (int)fieldOffset;

            if (buffer == null)
            {
                return((long)length1);
            }
            try
            {
                if (sourceIndex < length1)
                {
                    if (sourceIndex + length > length1)
                    {
                        length1 -= sourceIndex;
                    }
                    else
                    {
                        length1 = length;
                    }
                }
                Array.Copy((Array)numArray, sourceIndex, (Array)buffer, bufferOffset, length1);
            }
            catch (Exception ex)
            {
                if (ex.IsCatchableExceptionType())
                {
                    int length2 = numArray.Length;
                    if (length < 0)
                    {
                        throw new IndexOutOfRangeException(Strings.ADP_InvalidDataLength((object)((long)length).ToString((IFormatProvider)CultureInfo.InvariantCulture)));
                    }
                    if (bufferOffset < 0 || bufferOffset >= buffer.Length)
                    {
                        throw new ArgumentOutOfRangeException(nameof(bufferOffset), Strings.ADP_InvalidDestinationBufferIndex((object)length.ToString((IFormatProvider)CultureInfo.InvariantCulture), (object)bufferOffset.ToString((IFormatProvider)CultureInfo.InvariantCulture)));
                    }
                    if (fieldOffset < 0L || fieldOffset >= (long)length2)
                    {
                        throw new ArgumentOutOfRangeException(nameof(fieldOffset), Strings.ADP_InvalidSourceBufferIndex((object)length.ToString((IFormatProvider)CultureInfo.InvariantCulture), (object)fieldOffset.ToString((IFormatProvider)CultureInfo.InvariantCulture)));
                    }
                    if (length2 + bufferOffset > buffer.Length)
                    {
                        throw new IndexOutOfRangeException(Strings.ADP_InvalidBufferSizeOrIndex((object)length2.ToString((IFormatProvider)CultureInfo.InvariantCulture), (object)bufferOffset.ToString((IFormatProvider)CultureInfo.InvariantCulture)));
                    }
                }
                throw;
            }
            return((long)length1);
        }
Exemple #5
0
        public override long GetChars(
            int ordinal,
            long fieldOffset,
            char[] buffer,
            int bufferOffset,
            int length)
        {
            string str   = (string)this._values[ordinal];
            int    count = str.Length;

            if (fieldOffset > (long)int.MaxValue)
            {
                throw new ArgumentOutOfRangeException(nameof(fieldOffset), Strings.ADP_InvalidSourceBufferIndex((object)count.ToString((IFormatProvider)CultureInfo.InvariantCulture), (object)fieldOffset.ToString((IFormatProvider)CultureInfo.InvariantCulture)));
            }
            int sourceIndex = (int)fieldOffset;

            if (buffer == null)
            {
                return((long)count);
            }
            try
            {
                if (sourceIndex < count)
                {
                    if (sourceIndex + length > count)
                    {
                        count -= sourceIndex;
                    }
                    else
                    {
                        count = length;
                    }
                }
                str.CopyTo(sourceIndex, buffer, bufferOffset, count);
            }
            catch (Exception ex)
            {
                if (ex.IsCatchableExceptionType())
                {
                    int length1 = str.Length;
                    if (length < 0)
                    {
                        throw new IndexOutOfRangeException(Strings.ADP_InvalidDataLength((object)((long)length).ToString((IFormatProvider)CultureInfo.InvariantCulture)));
                    }
                    if (bufferOffset < 0 || bufferOffset >= buffer.Length)
                    {
                        throw new ArgumentOutOfRangeException(nameof(bufferOffset), Strings.ADP_InvalidDestinationBufferIndex((object)buffer.Length.ToString((IFormatProvider)CultureInfo.InvariantCulture), (object)bufferOffset.ToString((IFormatProvider)CultureInfo.InvariantCulture)));
                    }
                    if (fieldOffset < 0L || fieldOffset >= (long)length1)
                    {
                        throw new ArgumentOutOfRangeException(nameof(fieldOffset), Strings.ADP_InvalidSourceBufferIndex((object)length1.ToString((IFormatProvider)CultureInfo.InvariantCulture), (object)fieldOffset.ToString((IFormatProvider)CultureInfo.InvariantCulture)));
                    }
                    if (length1 + bufferOffset > buffer.Length)
                    {
                        throw new IndexOutOfRangeException(Strings.ADP_InvalidBufferSizeOrIndex((object)length1.ToString((IFormatProvider)CultureInfo.InvariantCulture), (object)bufferOffset.ToString((IFormatProvider)CultureInfo.InvariantCulture)));
                    }
                }
                throw;
            }
            return((long)count);
        }