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 throwing ArgumentNullException #173

Closed
Tracked by #124
Seb-stian opened this issue Nov 3, 2021 · 3 comments · Fixed by #184
Closed
Tracked by #124

Refactor throwing ArgumentNullException #173

Seb-stian opened this issue Nov 3, 2021 · 3 comments · Fixed by #184
Assignees
Labels
code-style Relates to code formatting and conventions priority: low Nice to have

Comments

@Seb-stian
Copy link
Member

With .NET 6, this code

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

can be replaced by

ArgumentNullException.ThrowIfNull(foo, nameof(foo));

which is to be prefered.

@Seb-stian Seb-stian added future This feature will be worked on in the future priority: low Nice to have code-style Relates to code formatting and conventions labels Nov 3, 2021
@Seb-stian Seb-stian added this to the Upgrade to .NET 6 milestone Nov 3, 2021
@Seb-stian Seb-stian mentioned this issue Nov 3, 2021
6 tasks
@Craftplacer
Copy link
Collaborator

Wasn't it possible before to Property = argument ?? throw new ArgumentNullException(nameof(argument));?

@Seb-stian
Copy link
Member Author

Wasn't it possible before to Property = argument ?? throw new ArgumentNullException(nameof(argument));?

Yes it was, but when simply null-checking method arguments, you would have to do something like

_ = arg ?? throw new ArgumentNullException(nameof(arg));

@Craftplacer
Copy link
Collaborator

Craftplacer commented Nov 6, 2021

I guess that pattern stays constructor-exclusive for now.

@Naamloos Naamloos removed the future This feature will be worked on in the future label Nov 8, 2021
@Seb-stian Seb-stian self-assigned this Nov 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code-style Relates to code formatting and conventions priority: low Nice to have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants