Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply ArgumentNullException.ThrowIfNull to NLog source-code #623

Closed
snakefoot opened this issue Sep 3, 2022 · 0 comments · Fixed by #646
Closed

Apply ArgumentNullException.ThrowIfNull to NLog source-code #623

snakefoot opened this issue Sep 3, 2022 · 0 comments · Fixed by #646

Comments

@snakefoot
Copy link
Contributor

snakefoot commented Sep 3, 2022

Has been introduced with NET6, but it should be "easy" to implement equal solution in NLog.Internal:

From:

            if (factory is null)
            {
                throw new ArgumentNullException(nameof(factory));
            }

To

           ArgumentNullException.ThrowIfNull(factory);

From:

            _logger = logger ?? throw new ArgumentNullException(nameof(logger));

To:

           _logger = ArgumentNullException.ThrowIfNull(logger);

https://docs.microsoft.com/en-us/dotnet/api/system.argumentnullexception.throwifnull?view=net-6.0

Ex.

static internal class ArgumentNullException
{
    public static T ThrowIfNull<T>(T argument, [CallerArgumentExpression("argument")] string paramName = null)
        where T : class
    {
        if (argument is null)
        {
            throw new System.ArgumentNullException(paramName);
        }

        return argument;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant