-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArgumentNullExceptionHelper.cs
More file actions
33 lines (30 loc) · 1.28 KB
/
ArgumentNullExceptionHelper.cs
File metadata and controls
33 lines (30 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Portions of this file have been borrowed from <https://github.com/dotnet/runtime> with the following license notice:
//
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//
// Only trivial changes have been made to the borrowed source code, such as formatting and modern C# features.
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
namespace System
{
internal static class ArgumentNullExceptionHelper
{
/// <summary>Throws an <see cref="ArgumentNullException"/> if <paramref name="argument"/> is null.</summary>
/// <param name="argument">The reference type argument to validate as non-null.</param>
/// <param name="paramName">The name of the parameter with which <paramref name="argument"/> corresponds.</param>
public static void ThrowIfNull
(
[NotNull] object? argument,
[CallerArgumentExpression(nameof(argument))] string? paramName = null
)
{
if (argument is null)
{
Throw(paramName);
}
}
[DoesNotReturn]
private static void Throw(string? paramName) => throw new ArgumentNullException(paramName);
}
}