// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
namespace CommunityToolkit.Mvvm;
///
/// Internal polyfill for .
///
internal sealed class ArgumentNullException
{
///
/// Throws an if is .
///
/// The reference type argument to validate as non-.
/// The name of the parameter with which corresponds.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ThrowIfNull([NotNull] object? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
{
if (argument is null)
{
Throw(paramName);
}
}
///
/// A specialized version for generic values.
///
/// The type of values to check.
///
/// This type is needed because if there had been a generic overload with a generic parameter, all calls
/// would have just been bound by that by the compiler instead of the overload.
///
public static class For
{
///
/// Throws an if is .
///
/// The reference type argument to validate as non-.
/// The name of the parameter with which corresponds.
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ThrowIfNull([NotNull] T? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
{
if (argument is null)
{
Throw(paramName);
}
}
}
///
/// Throws an .
///
/// The name of the parameter that failed validation.
[DoesNotReturn]
private static void Throw(string? paramName)
{
throw new System.ArgumentNullException(paramName);
}
}