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

Fix AgainstExpression to be Expression #309

Open
ardalis opened this issue Nov 21, 2023 · 2 comments
Open

Fix AgainstExpression to be Expression #309

ardalis opened this issue Nov 21, 2023 · 2 comments
Labels
bug good first issue help wanted .NET Pull requests that update .net code

Comments

@ardalis
Copy link
Owner

ardalis commented Nov 21, 2023

Currently when using the expression guard you have to write code like this:

Guard.Against.AgainstExpression(x => false, input, "error");

which obviously has "Against" in it twice and comes across as a double negative. It's also not clear (to me at least without reading the docs/ viewing the source) whether the expression should describe the "happy path" or the "invalid path". It would be more clear if I knew I was guarding against something I did not want, and then the expression would describe the INVALID state.

How to Implement:

  1. Mark AgainstExpression as obsolete.
  2. Create Expression or name similar if we can't use that name and have it do the same thing.
  3. Consider using CallerArgumentExpression in the parameter list if that makes sense.
  4. Make sure it's super clear that the expression should be the negative, invalid case. When it's true, that means the input is BAD, and an exception will be thrown.

After we publish the two side-by-side I will remove the obsolete one in a future version.

@ardalis ardalis added bug help wanted good first issue .NET Pull requests that update .net code labels Nov 21, 2023
@SimonNyvall
Copy link
Contributor

How would you like it to me mark as obsolete? I guess you would still be able to call it but maybe a note in the summary?

@ardalis
Copy link
Owner Author

ardalis commented Nov 22, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug good first issue help wanted .NET Pull requests that update .net code
Projects
None yet
Development

No branches or pull requests

2 participants