Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public override long GetBytes(int ordinal, long fieldOffset, byte[] buffer, int bufferOffset, int length)
        {
            var cbytes = 0;
            int ndataIndex;

            var data = (byte[])_values[ordinal];

            cbytes = 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(
                              cbytes.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(cbytes);
            }

            try
            {
                if (ndataIndex < cbytes)
                {
                    // help the user out in the case where there's less data than requested
                    if ((ndataIndex + length) > cbytes)
                    {
                        cbytes = cbytes - ndataIndex;
                    }
                    else
                    {
                        cbytes = length;
                    }
                }

                Array.Copy(data, ndataIndex, buffer, bufferOffset, cbytes);
            }
            catch (Exception e)
            {
                if (e.IsCatchableExceptionType())
                {
                    cbytes = 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(
                                      length.ToString(CultureInfo.InvariantCulture), bufferOffset.ToString(CultureInfo.InvariantCulture)));
                    }

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

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

                throw;
            }

            return(cbytes);
        }
Ejemplo n.º 3
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);
        }