-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Use CallerArgumentExpression for internal assert-like constructs #10812
base: main
Are you sure you want to change the base?
Conversation
But don't use it anywhere yet.
Includes some nullability adjustments to work with the new paradigm.
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.
Great refactoring! Great separation into the reviawable chunks! I love this!
I only have small nonblocking nitpicks
@@ -467,7 +468,7 @@ internal static void VerifyThrowArgument([DoesNotReturnIf(false)] bool condition | |||
/// Throws an argument out of range exception. | |||
/// </summary> | |||
[DoesNotReturn] | |||
internal static void ThrowArgumentOutOfRange(string parameterName) | |||
internal static void ThrowArgumentOutOfRange(string? parameterName) |
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.
Why is this needed? - I'd expect this change to not cause weaker nullability guarantee
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.
Yeah this is a bit unfortunate. To use [CallerMemberName]
you have to provide a default value, and the one for string parameterName
that makes the most sense IMO is null
. But then there's a possibility that null
flows through the other overload of ThrowArgumentOutOfRange
to here.
I think I prefer this to swapping it for ""
but if you feel strongly the other way I can swap it. Definitely not a strong preference on my side.
a1017ea
to
96592c8
Compare
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
From ``` ErrorUtilities\.VerifyThrowArgumentNull\(([a-zA-Z0-9]+), nameof\(\1\)\); ``` to ``` ErrorUtilities.VerifyThrowArgumentNull($1); ``` (And then revert `src/Deprecated`.)
From ``` ErrorUtilities\.VerifyThrowArgumentLength\(([a-zA-Z0-9]+), nameof\(\1\)\); ``` to ``` ErrorUtilities.VerifyThrowArgumentLength($1); ``` And revert `src/Deprecated`.
From ``` ErrorUtilities\.VerifyThrowInternalNull\(([a-zA-Z0-9]+), nameof\(\1\)\); ``` to ``` ErrorUtilities.VerifyThrowInternalNull($1); ``` and revert `src/Deprecated`.
96592c8
to
5b7ef3c
Compare
on macOS??? |
CallerArgumentExpression
is a new (C# 10) language feature that allows us to simplify a bunch of our assert-like code to drop the redundant specifications of, like, "which argument isnull
?".I strongly recommend reviewing commit-by-commit; the bulk of the changes are a regex replace on top of a framework that is fairly small.