Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Use [CallerArgumentExpression] to simplify calling patterns into Requires class #165

Merged
merged 2 commits into from
Jan 27, 2023

Conversation

AArnott
Copy link
Member

@AArnott AArnott commented Jan 27, 2023

Closes #127

@AArnott AArnott changed the title Caller argument expression Use [CallerArgumentExpression] to simplify calling patterns into Requires class Jan 27, 2023
@RyanToth3
Copy link
Member

Very cool, big fan of this change!

@MichaelPeter
Copy link

Love it

@AArnott AArnott merged commit 99658f1 into microsoft:main Jan 27, 2023
@AArnott AArnott deleted the CallerArgumentExpression branch January 27, 2023 14:03
@jdrobison
Copy link
Member

Late to the party here, but +1 on the "love it" comments!

Question: this works even when targeting .NET Framework, correct?

@AArnott
Copy link
Member Author

AArnott commented Jan 27, 2023

Correct, @jdrobison. The only requirement is that you have a VS 2022 era C# compiler.

@drewnoakes
Copy link
Member

drewnoakes commented Jan 28, 2023

Amazing, thank you for changing this!

For anyone now facing a mass migration, the following RegEx might be helpful. In VS's Replace in files:

  • Requires\.NotNull\((\w+), nameof\(\1\)\);
  • Requires.NotNull($1);

image

Also:

  • Requires.NotNullAllowStructs
  • Requires.NotNullOrEmpty
  • Requires.NotNullOrWhiteSpace
  • Requires.NullOrNotNullElements
  • Requires.NotNullEmptyOrNullElements
  • Requires.NotEmpty
  • Requires.Defined
  • Requires.NotDefault

Calls to Assumes.True(bool, string) and Assumes.False(bool, string) likely require manual review.

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

Successfully merging this pull request may close these issues.

Support CallerArgumentExpression in assertions
5 participants