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

Suggestion. Make it one liner. #30

Open
Bartmax opened this issue Aug 13, 2015 · 1 comment
Open

Suggestion. Make it one liner. #30

Bartmax opened this issue Aug 13, 2015 · 1 comment

Comments

@Bartmax
Copy link

Bartmax commented Aug 13, 2015

Instead of

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

I like this better:

if (param == null) throw new ArgumentNullException(nameof(param));
@sharwell
Copy link
Member

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));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants