ThrowIndexOutOfRangeException() static private method

static private ThrowIndexOutOfRangeException ( ) : void
return void
Esempio n. 1
0
        public static void Clear(Array array, int index, int length)
        {
            if (array == null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
            }
            if (length < 0)
            {
                ThrowHelper.ThrowIndexOutOfRangeException();
            }

            int low = array.GetLowerBound(0);

            if (index < low)
            {
                ThrowHelper.ThrowIndexOutOfRangeException();
            }

            index = index - low;

            // re-ordered to avoid possible integer overflow
            if (index > array.Length - length)
            {
                ThrowHelper.ThrowIndexOutOfRangeException();
            }

            ClearInternal(array, index, length);
        }
Esempio n. 2
0
        /// <summary>
        /// Returns a reference to specified element of the Span.
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        /// <exception cref="System.IndexOutOfRangeException">
        /// Thrown when index less than 0 or index greater than or equal to Length
        /// </exception>

        // TODO: https://github.com/dotnet/corefx/issues/13681
        //   Until we get over the hurdle of C# 7 tooling, this temporary method will simulate the intended "ref T" indexer for those
        //   who need bypass the workaround for performance.
        //[MethodImpl(MethodImplOptions.AggressiveInlining)]
        public ref T GetItem(int index)
        {
            if ((uint)index >= ((uint)_length))
            {
                ThrowHelper.ThrowIndexOutOfRangeException();
            }

            return(ref Unsafe.Add(ref _pointer.Value, index));
        }
Esempio n. 3
0
        public char this [int index] {
            [Intrinsic]
            get {
                if ((uint)index >= _stringLength)
                {
                    ThrowHelper.ThrowIndexOutOfRangeException();
                }

                return(Unsafe.Add(ref _firstChar, index));
            }
        }
Esempio n. 4
0
 public char this[int index]
 {
     [Intrinsic]
     get
     {
         if ((uint)index >= (uint)_stringLength)
         {
             ThrowHelper.ThrowIndexOutOfRangeException();
         }
         return(Unsafe.Add(ref _firstChar, (nint)(uint)index /* force zero-extension */));
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Fetches the element at the specified index.
        /// </summary>
        /// <exception cref="System.IndexOutOfRangeException">
        /// Thrown when the specified <paramref name="index"/> is not in range (&lt;0 or &gt;&eq;Length).
        /// </exception>
        public T this[int index]
        {
            get
            {
                if ((uint)index >= (uint)_length)
                {
                    ThrowHelper.ThrowIndexOutOfRangeException();
                }

                return(Unsafe.Add(ref DangerousGetPinnableReference(), index));
            }
        }
        /// <summary>
        /// Fetches the element at the specified index.
        /// </summary>
        /// <exception cref="System.IndexOutOfRangeException">
        /// Thrown when the specified <paramref name="index"/> is not in range (&lt;0 or &gt;&eq;Length).
        /// </exception>
        public T this[int index]
        {
            get
            {
                if ((uint)index >= (uint)_length)
                {
                    ThrowHelper.ThrowIndexOutOfRangeException();
                }

                return(Unsafe.Add(ref GetRawPointer(), index));
            }
        }
Esempio n. 7
0
File: Span.cs Progetto: xen2/coreclr
        /// <summary>
        /// Returns a reference to specified element of the Span.
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        /// <exception cref="System.IndexOutOfRangeException">
        /// Thrown when index less than 0 or index greater than or equal to Length
        /// </exception>
        public ref T this[int index]
        {
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            get
            {
                if ((uint)index >= (uint)_length)
                {
                    ThrowHelper.ThrowIndexOutOfRangeException();
                }

                return(ref Unsafe.Add(ref _pointer.Value, index));
            }
        }
Esempio n. 8
0
 /// <summary>
 /// Returns the specified element of the read-only span.
 /// </summary>
 /// <param name="index"></param>
 /// <returns></returns>
 /// <exception cref="System.IndexOutOfRangeException">
 /// Thrown when index less than 0 or index greater than or equal to Length
 /// </exception>
 public ref readonly T this[int index]
 {
     [Intrinsic]
     [MethodImpl(MethodImplOptions.AggressiveInlining)]
     [NonVersionable]
     get
     {
         if ((uint)index >= (uint)_length)
         {
             ThrowHelper.ThrowIndexOutOfRangeException();
         }
         return(ref Unsafe.Add(ref _pointer.Value, index));
     }
 }
Esempio n. 9
0
 /// <summary>
 /// Returns a reference to specified element of the Span.
 /// </summary>
 /// <param name="index"></param>
 /// <returns></returns>
 /// <exception cref="System.IndexOutOfRangeException">
 /// Thrown when index less than 0 or index greater than or equal to Length
 /// </exception>
 public ref T this[int index]
 {
     [Intrinsic]
     [MethodImpl(MethodImplOptions.AggressiveInlining)]
     [NonVersionable]
     get
     {
         if ((uint)index >= (uint)_length)
         {
             ThrowHelper.ThrowIndexOutOfRangeException();
         }
         return(ref Unsafe.Add(ref _reference, (nint)(uint)index /* force zero-extension */));
     }
 }
Esempio n. 10
0
        public ref T GetItem(int index)
        {
            if ((uint)index >= ((uint)_length))
            {
                ThrowHelper.ThrowIndexOutOfRangeException();
            }

            if (_pinnable == null)
            {
                unsafe { return(ref Unsafe.Add <T>(ref Unsafe.AsRef <T>(_byteOffset.ToPointer()), index)); }
            }
            else
            {
                return(ref Unsafe.Add <T>(ref Unsafe.AddByteOffset <T>(ref _pinnable.Data, _byteOffset), index));
            }
        }
Esempio n. 11
0
        public static unsafe void Clear(Array array, int index, int length)
        {
            if (array == null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
            }

            int   lowerBound    = array.GetLowerBound(0);
            int   elementSize   = array.GetElementSize();
            nuint numComponents = (nuint)Unsafe.As <RawData> (array).Count;

            int offset = index - lowerBound;

            if (index < lowerBound || offset < 0 || length < 0 || (uint)(offset + length) > numComponents)
            {
                ThrowHelper.ThrowIndexOutOfRangeException();
            }

            ref byte ptr        = ref Unsafe.AddByteOffset(ref array.GetRawSzArrayData(), (uint)offset * (nuint)elementSize);
Esempio n. 12
0
        /// <summary>
        /// Returns the specified element of the read-only span.
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        /// <exception cref="System.IndexOutOfRangeException">
        /// Thrown when index less than 0 or index greater than or equal to Length
        /// </exception>
        public ref readonly T this[int index]
        {
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            get
            {
                if ((uint)index >= ((uint)_length))
                {
                    ThrowHelper.ThrowIndexOutOfRangeException();
                }

                if (_pinnable == null)
                {
                    unsafe { return(ref Unsafe.Add <T>(ref Unsafe.AsRef <T>(_byteOffset.ToPointer()), index)); }
                }
                else
                {
                    return(ref Unsafe.Add <T>(ref Unsafe.AddByteOffset <T>(ref _pinnable.Data, _byteOffset), index));
                }
            }
        }