static private ThrowArgumentOutOfRangeException ( ExceptionArgument argument ) : void | ||
argument | ExceptionArgument | |
Результат | void |
// Converts an array of bytes into a char. public static char ToChar(byte[] value, int startIndex) { if (value == null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value); } if ((uint)startIndex >= value.Length) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); } if (startIndex > value.Length - 2) { ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall); } Contract.EndContractBlock(); return((char)ToInt16(value, startIndex)); }
public static unsafe void MemoryCopy(void *source, void *destination, ulong destinationSizeInBytes, ulong sourceBytesToCopy) { if (sourceBytesToCopy > destinationSizeInBytes) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.sourceBytesToCopy); } var src = (byte *)source; var dst = (byte *)destination; while (sourceBytesToCopy > int.MaxValue) { Memcpy(dst, src, int.MaxValue); sourceBytesToCopy -= int.MaxValue; src += int.MaxValue; dst += int.MaxValue; } Memcpy(dst, src, (int)sourceBytesToCopy); }
public static bool IsSymbol(string s, int index) { if (s == null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s); } if (((uint)index) >= ((uint)s.Length)) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index); } char c = s[index]; if (IsLatin1(c)) { return(CheckSymbol(GetLatin1UnicodeCategory(c))); } return(CheckSymbol(CharUnicodeInfo.GetUnicodeCategoryInternal(s, index))); }
public static bool IsUpper(string s, int index) { if (s == null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s); } if (((uint)index) >= ((uint)s.Length)) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index); } char c = s[index]; if (IsLatin1(c)) { return((Latin1CharInfo[c] & IsUpperCaseLetterFlag) != 0); } return(CharUnicodeInfo.GetUnicodeCategoryInternal(s, index) == UnicodeCategory.UppercaseLetter); }
public static bool IsDigit(string s, int index) { if (s == null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s); } if (((uint)index) >= ((uint)s.Length)) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index); } char c = s[index]; if (IsLatin1(c)) { return(IsInRange(c, '0', '9')); } return(CharUnicodeInfo.GetUnicodeCategoryInternal(s, index) == UnicodeCategory.DecimalDigitNumber); }
public ReadOnlyMemory(T[] array, int start, int length) { if (array == null) { if (start != 0 || length != 0) { ThrowHelper.ThrowArgumentOutOfRangeException(); } this = default; return; // returns default } if ((uint)start > (uint)array.Length || (uint)length > (uint)(array.Length - start)) { ThrowHelper.ThrowArgumentOutOfRangeException(); } _object = array; _index = start; _length = length; }
[System.Security.SecuritySafeCritical] // auto-generated unsafe public static double ToDouble(byte[] value, int startIndex) { if (value == null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value); } if ((uint)startIndex >= value.Length) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); } if (startIndex > value.Length - 8) { ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall); } Contract.EndContractBlock(); long val = ToInt64(value, startIndex); return(*(double *)&val); }
public ReadOnlySpan(T[] array, int start, int length) { if (array == null) { if (start != 0 || length != 0) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start); } this = default; return; // returns default } if ((uint)start > (uint)array.Length || (uint)length > (uint)(array.Length - start)) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start); } _length = length; _pinnable = Unsafe.As <Pinnable <T> >(array); _byteOffset = SpanHelpers.PerTypeValues <T> .ArrayAdjustment.Add <T>(start); }
[System.Security.SecuritySafeCritical] // auto-generated public static unsafe long ToInt64(byte[] value, int startIndex) { if (value == null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value); } if ((uint)startIndex >= value.Length) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); } if (startIndex > value.Length - 8) { ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall); } Contract.EndContractBlock(); fixed(byte *pbyte = &value[startIndex]) { if (startIndex % 8 == 0) // data is aligned { return(*((long *)pbyte)); } else { if (IsLittleEndian) { int i1 = (*pbyte) | (*(pbyte + 1) << 8) | (*(pbyte + 2) << 16) | (*(pbyte + 3) << 24); int i2 = (*(pbyte + 4)) | (*(pbyte + 5) << 8) | (*(pbyte + 6) << 16) | (*(pbyte + 7) << 24); return((uint)i1 | ((long)i2 << 32)); } else { int i1 = (*pbyte << 24) | (*(pbyte + 1) << 16) | (*(pbyte + 2) << 8) | (*(pbyte + 3)); int i2 = (*(pbyte + 4) << 24) | (*(pbyte + 5) << 16) | (*(pbyte + 6) << 8) | (*(pbyte + 7)); return((uint)i2 | ((long)i1 << 32)); } } } }
public int IndexOfAny(char[] anyOf, int startIndex, int count) { if (anyOf is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.anyOf); } if ((uint)startIndex > (uint)Length) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_IndexMustBeLessOrEqual); } if ((uint)count > (uint)(Length - startIndex)) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_Count); } int result = new ReadOnlySpan <char>(ref Unsafe.Add(ref _firstChar, startIndex), count).IndexOfAny(anyOf); return(result < 0 ? result : result + startIndex); }
public T this[int index] { get { if ((uint)index >= (uint)_count) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index); } return(_array[_offset + index]); } set { if ((uint)index >= (uint)_count) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index); } _array[_offset + index] = value; } }
public static bool IsLetter(string s, int index) { if (s == null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s); } if (((uint)index) >= ((uint)s.Length)) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index); } char c = s[index]; if (IsAscii(c)) { // The ASCII range doesn't include letters in categories other than "upper" and "lower" return((Latin1CharInfo[c] & (IsUpperCaseLetterFlag | IsLowerCaseLetterFlag)) != 0); } return(CheckLetter(CharUnicodeInfo.GetUnicodeCategoryInternal(s, index))); }
public ReadOnlySpan(T[]? array, int start, int length) { if (array == null) { if (start != 0 || length != 0) ThrowHelper.ThrowArgumentOutOfRangeException(); this = default; return; // returns default } #if BIT64 // See comment in Span<T>.Slice for how this works. if ((ulong)(uint)start + (ulong)(uint)length > (ulong)(uint)array.Length) ThrowHelper.ThrowArgumentOutOfRangeException(); #else if ((uint)start > (uint)array.Length || (uint)length > (uint)(array.Length - start)) ThrowHelper.ThrowArgumentOutOfRangeException(); #endif _pointer = new ByReference<T>(ref Unsafe.Add(ref Unsafe.As<byte, T>(ref array.GetRawSzArrayData()), start)); _length = length; }
/// <summary> /// Creates a new span over the portion of the target array beginning /// at 'start' index and ending at 'end' index (exclusive). /// </summary> /// <param name="array">The target array.</param> /// <param name="start">The index at which to begin the span.</param> /// <param name="length">The number of items in the span.</param> /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="array"/> is a null /// reference (Nothing in Visual Basic).</exception> /// <exception cref="System.ArrayTypeMismatchException">Thrown when <paramref name="array"/> is covariant and array's type is not exactly T[].</exception> /// <exception cref="System.ArgumentOutOfRangeException"> /// Thrown when the specified <paramref name="start"/> or end index is not in the range (<0 or >=Length). /// </exception> public Span(T[] array, int start, int length) { if (array == null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } if (default(T) == null) // Arrays of valuetypes are never covariant { if (array.GetType() != typeof(T[])) { ThrowHelper.ThrowArrayTypeMismatchException(); } } if ((uint)start > (uint)array.Length || (uint)length > (uint)(array.Length - start)) { ThrowHelper.ThrowArgumentOutOfRangeException(); } _pointer = new ByReference <T>(ref Unsafe.Add(ref JitHelpers.GetArrayData(array), start)); _length = length; }
public static void Resize <T>(ref T[] array, int newSize) { if (newSize < 0) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.newSize, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); } T[] larray = array; if (larray == null) { array = new T[newSize]; return; } if (larray.Length != newSize) { T[] newArray = new T[newSize]; Array.Copy(larray, 0, newArray, 0, larray.Length > newSize ? newSize : larray.Length); array = newArray; } }
public unsafe int LastIndexOf(char value, int startIndex, int count) { if (Length == 0) { return(-1); } if ((uint)startIndex >= (uint)Length) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_IndexMustBeLess); } if ((uint)count > (uint)startIndex + 1) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_Count); } int startSearchAt = startIndex + 1 - count; int result = SpanHelpers.LastIndexOfValueType(ref Unsafe.As <char, short>(ref Unsafe.Add(ref _firstChar, startSearchAt)), (short)value, count); return(result < 0 ? result : result + startSearchAt); }
public Span(T[] array, int start) { if (array == null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } if (default(T) == null && array.GetType() != typeof(T[])) { ThrowHelper.ThrowArrayTypeMismatchException_ArrayTypeMustBeExactMatch(typeof(T)); } int arrayLength = array.Length; if ((uint)start > (uint)arrayLength) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start); } _length = arrayLength - start; _pinnable = Unsafe.As <Pinnable <T> >(array); _byteOffset = SpanHelpers.PerTypeValues <T> .ArrayAdjustment.Add <T>(start); }
// Skips zero-initialization of the array if possible. If T contains object references, // the array is always zero-initialized. internal static T[] AllocateUninitializedArray <T>(int length) { if (length < 0) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.lengths, 0, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); } #if DEBUG // in DEBUG arrays of any length can be created uninitialized #else // otherwise small arrays are allocated using `new[]` as that is generally faster. // // The threshold was derived from various simulations. // As it turned out the threshold depends on overal pattern of all allocations and is typically in 200-300 byte range. // The gradient around the number is shallow (there is no perf cliff) and the exact value of the threshold does not matter a lot. // So it is 256 bytes including array header. if (Unsafe.SizeOf <T>() * length < 256 - 3 * IntPtr.Size) { return(new T[length]); } #endif return((T[])AllocateNewArray(typeof(T[]).TypeHandle.Value, length, zeroingOptional: true)); }
public ReadOnlyMemory <T> Slice(int start, int length) { // Used to maintain the high-bit which indicates whether the Memory has been pre-pinned or not. int capturedLength = _length; int actualLength = _length & RemoveFlagsBitMask; #if BIT64 // See comment in Span<T>.Slice for how this works. if ((ulong)(uint)start + (ulong)(uint)length > (ulong)(uint)actualLength) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start); } #else if ((uint)start > (uint)actualLength || (uint)length > (uint)(actualLength - start)) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.start); } #endif // Set the high-bit to match the this._length high bit (1 for pre-pinned, 0 for unpinned). return(new ReadOnlyMemory <T>(_object, _index + start, length | (capturedLength & ~RemoveFlagsBitMask))); }
public Utf8String Substring(int startIndex) { if ((uint)startIndex > (uint)this.Length) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex); } // Optimizations: since instances are immutable, we can return 'this' or the known // Empty instance if the caller passed us a startIndex at the string boundary. if (startIndex == 0) { return(this); } if (startIndex == Length) { return(Empty); } return(InternalSubstring(startIndex, Length - startIndex)); }
internal static unsafe T[] AllocateUninitializedArray <T>(int length) { if (RuntimeHelpers.IsReferenceOrContainsReferences <T>()) { return(new T[length]); } if (length < 0) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.lengths, 0, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); } #if DEBUG // in DEBUG arrays of any length can be created uninitialized #else // otherwise small arrays are allocated using `new[]` as that is generally faster. // // The threshold was derived from various simulations. // As it turned out the threshold depends on overal pattern of all allocations and is typically in 200-300 byte range. // The gradient around the number is shallow (there is no perf cliff) and the exact value of the threshold does not matter a lot. // So it is 256 bytes including array header. if (Unsafe.SizeOf <T>() * length < 256 - 3 * IntPtr.Size) { return(new T[length]); } #endif var pEEType = EETypePtr.EETypePtrOf <T[]>(); T[] array = null; RuntimeImports.RhAllocateUninitializedArray(pEEType.RawValue, (uint)length, Unsafe.AsPointer(ref array)); if (array == null) { throw new OutOfMemoryException(); } return(array); }
public Span(T[] array, int start, int length) { if (array == null) { if (start != 0 || length != 0) { ThrowHelper.ThrowArgumentOutOfRangeException(); } this = default; return; // returns default } if (default(T) == null && array.GetType() != typeof(T[])) { ThrowHelper.ThrowArrayTypeMismatchException(); } if ((uint)start > (uint)array.Length || (uint)length > (uint)(array.Length - start)) { ThrowHelper.ThrowArgumentOutOfRangeException(); } _pointer = new ByReference <T>(ref Unsafe.Add(ref Unsafe.As <byte, T>(ref array.GetRawSzArrayData()), start)); _length = length; }
[System.Security.SecuritySafeCritical] // auto-generated public static unsafe int ToInt32(byte[] value, int startIndex) { if (value == null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value); } if ((uint)startIndex >= value.Length) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); } if (startIndex > value.Length - 4) { ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall); } Contract.EndContractBlock(); fixed(byte *pbyte = &value[startIndex]) { if (startIndex % 4 == 0) // data is aligned { return(*((int *)pbyte)); } else { if (IsLittleEndian) { return((*pbyte) | (*(pbyte + 1) << 8) | (*(pbyte + 2) << 16) | (*(pbyte + 3) << 24)); } else { return((*pbyte << 24) | (*(pbyte + 1) << 16) | (*(pbyte + 2) << 8) | (*(pbyte + 3))); } } } }
internal Memory(T[] array, int start) { if (array == null) { if (start != 0) { ThrowHelper.ThrowArgumentOutOfRangeException(); } this = default; return; // returns default } if (default(T) == null && array.GetType() != typeof(T[])) { ThrowHelper.ThrowArrayTypeMismatchException(); } if ((uint)start > (uint)array.Length) { ThrowHelper.ThrowArgumentOutOfRangeException(); } _object = array; _index = start; _length = array.Length - start; }
// Converts an array of bytes into a short. public static unsafe short ToInt16(byte[] value, int startIndex) { if (value == null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value); } if ((uint)startIndex >= value.Length) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); } if (startIndex > value.Length - 2) { ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall); } fixed(byte *pbyte = &value[startIndex]) { if (startIndex % 2 == 0) // data is aligned { return(*((short *)pbyte)); } else { if (IsLittleEndian) { return((short)((*pbyte) | (*(pbyte + 1) << 8))); } else { return((short)((*pbyte << 8) | (*(pbyte + 1)))); } } } }
internal Memory(T[]?array, int start) { if (array == null) { if (start != 0) { ThrowHelper.ThrowArgumentOutOfRangeException(); } this = default; return; // returns default } if (default(T) ! == null && array.GetType() != typeof(T[])) // TODO-NULLABLE: https://github.com/dotnet/roslyn/issues/34757 { ThrowHelper.ThrowArrayTypeMismatchException(); } if ((uint)start > (uint)array.Length) { ThrowHelper.ThrowArgumentOutOfRangeException(); } _object = array; _index = start; _length = array.Length - start; }
public static unsafe Array CreateInstance(Type elementType, int length1, int length2) { if (elementType is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.elementType); } if (length1 < 0) { ThrowHelper.ThrowArgumentOutOfRangeException( ExceptionArgument.length1, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum ); } if (length2 < 0) { ThrowHelper.ThrowArgumentOutOfRangeException( ExceptionArgument.length2, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum ); } RuntimeType?t = elementType.UnderlyingSystemType as RuntimeType; if (t == null) { ThrowHelper.ThrowArgumentException( ExceptionResource.Arg_MustBeType, ExceptionArgument.elementType ); } int *pLengths = stackalloc int[2]; pLengths[0] = length1; pLengths[1] = length2; return(InternalCreate((void *)t.TypeHandle.Value, 2, pLengths, null)); }
public ArraySegment(T[] array, int offset, int count) { if (array == null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array); } if (offset < 0) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.offset, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); } if (count < 0) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.count, ExceptionResource.ArgumentOutOfRange_NeedNonNegNum); } if (array.Length - offset < count) { ThrowHelper.ThrowArgumentException(ExceptionResource.Argument_InvalidOffLen); } Contract.EndContractBlock(); _array = array; _offset = offset; _count = count; }
// Converts an array of bytes into a String. public static string ToString(byte[] value, int startIndex, int length) { if (value == null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.value); } if (startIndex < 0 || startIndex >= value.Length && startIndex > 0) { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.startIndex, ExceptionResource.ArgumentOutOfRange_Index); } if (length < 0) { throw new ArgumentOutOfRangeException(nameof(length), SR.ArgumentOutOfRange_GenericPositive); } if (startIndex > value.Length - length) { ThrowHelper.ThrowArgumentException(ExceptionResource.Arg_ArrayPlusOffTooSmall, ExceptionArgument.value); } if (length == 0) { return(string.Empty); } if (length > (int.MaxValue / 3)) { // (Int32.MaxValue / 3) == 715,827,882 Bytes == 699 MB throw new ArgumentOutOfRangeException(nameof(length), SR.Format(SR.ArgumentOutOfRange_LengthTooLarge, (int.MaxValue / 3))); } #if __MonoCS__ //use old impl for mcs const string HexValues = "0123456789ABCDEF"; int chArrayLength = length * 3; char[] chArray = new char[chArrayLength]; int i = 0; int index = startIndex; for (i = 0; i < chArrayLength; i += 3) { byte b = value[index++]; chArray[i] = HexValues[b >> 4]; chArray[i + 1] = HexValues[b & 0xF]; chArray[i + 2] = '-'; } return(new String(chArray, 0, chArray.Length - 1)); #else return(string.Create(length * 3 - 1, (value, startIndex, length), (dst, state) => { const string HexValues = "0123456789ABCDEF"; var src = new ReadOnlySpan <byte>(state.value, state.startIndex, state.length); int i = 0; int j = 0; byte b = src[i++]; dst[j++] = HexValues[b >> 4]; dst[j++] = HexValues[b & 0xF]; while (i < src.Length) { b = src[i++]; dst[j++] = '-'; dst[j++] = HexValues[b >> 4]; dst[j++] = HexValues[b & 0xF]; } })); #endif }
internal static void ThrowArgumentOutOfRangeException() { ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument.index, ExceptionResource.ArgumentOutOfRange_Index); }