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

Refactor - Apply ThrowIfNull and ThrowIfNullOrEmpty #5216

Merged
merged 2 commits into from May 25, 2023
Merged

Refactor - Apply ThrowIfNull and ThrowIfNullOrEmpty #5216

merged 2 commits into from May 25, 2023

Conversation

nih0n
Copy link
Contributor

@nih0n nih0n commented May 11, 2023

Resolves #5055

Changes

Added Guard class with two methods

static T ThrowIfNull<T>(T arg, [CallerArgumentExpression("arg")] string param = "")
static string ThrowIfNullOrEmpty(string arg, [CallerArgumentExpression("arg")] string param = "")

and replaced all occurrences of

if (arg is null)
    throw new ArgumentNullException(nameof(arg));

// and

if (string.IsNullOrEmpty(arg))
    throw new ArgumentNullException(nameof(arg));

Remarks

This is the only line that we use the message parameter of ArgumentNullException so I didn't wanted to include it in the Guard methods

throw new ArgumentNullException(nameof(name), "Name of logger cannot be null");

This check is in a different assembly so I didn't added the refence to the Guard. I don't know if it would be ok.

throw new ArgumentNullException(nameof(fact));

@sonarcloud
Copy link

sonarcloud bot commented May 11, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

93.6% 93.6% Coverage
0.0% 0.0% Duplication

@snakefoot
Copy link
Contributor

snakefoot commented May 11, 2023

Thank you so much, and again sorry about the trouble.

It seems like the obsolete-adventure for NLog v5.2 is almost done. Just need to make a T4-template to replace NLog-Assembly-Scanning. Then everything can be merged.

@snakefoot snakefoot added this to the 5.2 milestone May 18, 2023
@snakefoot snakefoot merged commit 33d0a70 into NLog:dev May 25, 2023
5 checks passed
@snakefoot
Copy link
Contributor

snakefoot commented May 25, 2023

Finally able to start preparing the NLog v5.2 release with support for NET Trimming.

Thank you again for this nice codef-refactoring.

@nih0n nih0n deleted the apply-throw-if-null branch May 25, 2023 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Apply ArgumentNullException.ThrowIfNull to NLog source-code
2 participants