ThrowIndexOutOfRangeException() static private method

static private ThrowIndexOutOfRangeException ( ) : void
return void
コード例 #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);
        }
コード例 #2
0
ファイル: Span.cs プロジェクト: code4t2/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>

        // 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));
        }
コード例 #3
0
ファイル: String.Mono.cs プロジェクト: vivedu-lxzhai/mono
        public char this [int index] {
            [Intrinsic]
            get {
                if ((uint)index >= _stringLength)
                {
                    ThrowHelper.ThrowIndexOutOfRangeException();
                }

                return(Unsafe.Add(ref _firstChar, index));
            }
        }
コード例 #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 */));
     }
 }
コード例 #5
0
ファイル: ReadOnlySpan.cs プロジェクト: ppay502/coreclr
        /// <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));
            }
        }
コード例 #6
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 GetRawPointer(), index));
            }
        }
コード例 #7
0
ファイル: Span.cs プロジェクト: 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));
            }
        }
コード例 #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));
     }
 }
コード例 #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 */));
     }
 }
コード例 #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));
            }
        }
コード例 #11
0
ファイル: Array.Mono.cs プロジェクト: vivedu-lxzhai/mono
        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);
コード例 #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));
                }
            }
        }