ThrowArgumentNullException() static private method

static private ThrowArgumentNullException ( ExceptionArgument argument ) : void
argument ExceptionArgument
return void
Esempio n. 1
0
        // 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
        }
Esempio n. 2
0
 // Parses a long from a String in the given style.  If
 // a NumberFormatInfo isn't specified, the current culture's
 // NumberFormatInfo is assumed.
 //
 public static long Parse(string s, NumberStyles style, IFormatProvider? provider)
 {
     NumberFormatInfo.ValidateParseStyleInteger(style);
     if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
     return Number.ParseInt64(s, style, NumberFormatInfo.GetInstance(provider));
 }
Esempio n. 3
0
 public static long Parse(string s)
 {
     if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
     return Number.ParseInt64(s, NumberStyles.Integer, NumberFormatInfo.CurrentInfo);
 }
Esempio n. 4
0
 public static long Parse(string s, NumberStyles style)
 {
     NumberFormatInfo.ValidateParseStyleInteger(style);
     if (s == null) ThrowHelper.ThrowArgumentNullException(ExceptionArgument.s);
     return Number.ParseInt64(s, style, NumberFormatInfo.CurrentInfo);
 }
Esempio n. 5
0
 internal static void IfNullAndNullsAreIllegalThenThrow<T>(object value, ExceptionArgument argName)
 {
     // Note that default(T) is not equal to null for value types except when T is Nullable<U>.
     if (!(default(T) == null) && value == null)
         ThrowHelper.ThrowArgumentNullException(argName);
 }