-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Replace ArgumentNullException(nameof()) -> ArgumentNullException.ThrowIfNull() #18784
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
Replace ArgumentNullException(nameof()) -> ArgumentNullException.ThrowIfNull() #18784
Conversation
src/System.Management.Automation/utils/perfCounters/CounterSetRegistrarBase.cs
Outdated
Show resolved
Hide resolved
xtqqczze
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please address all feedback.
| { | ||
| throw new ArgumentNullException(nameof(optionName)); | ||
| } | ||
| ArgumentNullException.ThrowIfNull(optionName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please revert this change in behaviour.
|
@CarloToso sorry missed this was WIP. Perhaps you could "convert to draft". |
|
I tried to replace the results of this search: |
|
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
|
@CarloToso Thanks! I found ~71 lines with " ArgumentNullException(" patterns still not fixed. Some ones more complex. We could think about split some ones on two - for null, NullOrEmpty and for range (ArgumentOutOfRangeException). See also dotnet/roslyn-analyzers#6293 that we could fix too. Also we could update/replace |
|
Should we do something for |
Yes, it's worth it. |
PR Summary
Replaces all instances of:
with:
PR Context
Proposed in #18596
The new API ArgumentNullException.ThrowIfNull allows you to omit the parameter name, in which case it will use the name of the argument passed in. The passed in argument usually is the parameter to be validated, so that's just the right name to use when calling
ArgumentNullException.ThrowIfNull(argument).