Skip to content

Commit aa102f8

Browse files
committed
ArgumentNullException.ThrowIfNull Polyfill
1 parent 501ba00 commit aa102f8

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#if !NET6_0_OR_GREATER
2+
// ReSharper disable once CheckNamespace
3+
namespace Binkus.Compat;
4+
5+
using System.Diagnostics.CodeAnalysis;
6+
using System.Runtime.CompilerServices;
7+
// [TypeForwardedTo(typeof(global::System.ArgumentNullException))]
8+
public static class ArgumentNullException
9+
{
10+
/// <summary>Throws an <see cref="ArgumentNullException"/> if <paramref name="argument"/> is null.</summary>
11+
/// <param name="argument">The reference type argument to validate as non-null.</param>
12+
/// <param name="paramName">The name of the parameter with which <paramref name="argument"/> corresponds.</param>
13+
public static void ThrowIfNull([NotNull] object? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
14+
{
15+
if (argument is null) throw new global::System.ArgumentNullException(paramName);
16+
}
17+
}
18+
#endif

0 commit comments

Comments
 (0)