Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ public static void ThrowIfNull([NotNull] object? argument, [CallerArgumentExpres
}
}

internal static void ThrowIfNull([NotNull] object? argument, ExceptionArgument paramName)
{
if (argument is null)
{
ThrowHelper.ThrowArgumentNullException(paramName);
}
}

/// <summary>Throws an <see cref="ArgumentNullException"/> if <paramref name="argument"/> is null.</summary>
/// <param name="argument">The pointer argument to validate as non-null.</param>
/// <param name="paramName">The name of the parameter with which <paramref name="argument"/> corresponds.</param>
Expand Down
30 changes: 30 additions & 0 deletions src/libraries/System.Private.CoreLib/src/System/ThrowHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ internal static void ThrowArgumentException_DestinationTooShort()
throw new ArgumentException(SR.Argument_DestinationTooShort, "destination");
}

[DoesNotReturn]
internal static void ThrowArgumentException_InvalidTimeSpanStyles()
{
throw new ArgumentException(SR.Argument_InvalidTimeSpanStyles, "styles");
}

[DoesNotReturn]
internal static void ThrowArgumentException_OverlapAlignmentMismatch()
{
Expand Down Expand Up @@ -224,18 +230,36 @@ internal static void ThrowOverflowException()
throw new OverflowException();
}

[DoesNotReturn]
internal static void ThrowOverflowException_NegateTwosCompNum()
{
throw new OverflowException(SR.Overflow_NegateTwosCompNum);
}

[DoesNotReturn]
internal static void ThrowOverflowException_TimeSpanTooLong()
{
throw new OverflowException(SR.Overflow_TimeSpanTooLong);
}

[DoesNotReturn]
internal static void ThrowOverflowException_TimeSpanDuration()
{
throw new OverflowException(SR.Overflow_Duration);
}

[DoesNotReturn]
internal static void ThrowArgumentException_Arg_CannotBeNaN()
{
throw new ArgumentException(SR.Arg_CannotBeNaN);
}

[DoesNotReturn]
internal static void ThrowArgumentException_Arg_CannotBeNaN(ExceptionArgument argument)
{
throw new ArgumentException(SR.Arg_CannotBeNaN, GetArgumentName(argument));
}

[DoesNotReturn]
internal static void ThrowWrongKeyTypeArgumentException<T>(T key, Type targetType)
{
Expand Down Expand Up @@ -1000,6 +1024,10 @@ private static string GetArgumentName(ExceptionArgument argument)
return "overlapped";
case ExceptionArgument.minimumBytes:
return "minimumBytes";
case ExceptionArgument.divisor:
return "divisor";
case ExceptionArgument.factor:
return "factor";
default:
Debug.Fail("The enum value is not defined, please check the ExceptionArgument Enum.");
return "";
Expand Down Expand Up @@ -1289,6 +1317,8 @@ internal enum ExceptionArgument
anyOf,
overlapped,
minimumBytes,
divisor,
factor,
}

//
Expand Down
Loading