DotNetAnalyzers / NullParameterCheckRefactoring

Null Parameter Check Refactoring for Reference Type Parameters
MIT License
14 stars 4 forks source link

Suggestion. Make it one liner. #30

Open Bartmax opened 9 years ago

Bartmax commented 9 years ago

Instead of

if (param == null) 
{
     throw new ArgumentNullException(nameof(param));
}

I like this better:

if (param == null) throw new ArgumentNullException(nameof(param));
sharwell commented 9 years ago

I don't think braces are necessary here, but this is not the best way to make a single-line validation. If you want validation without a control flow block in code, use a helper method. This form is not only shorter than a single-line conditionally-thrown exception, but it is also much easier to read.

Requires.NotNull(param, nameof(param));