GuardClauses icon indicating copy to clipboard operation
GuardClauses copied to clipboard

Fix `AgainstExpression` to be `Expression`

Open ardalis opened this issue 2 years ago • 2 comments
trafficstars

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 avatar Nov 21 '23 22:11 ardalis

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?

SimonNyvall avatar Nov 22 '23 11:11 SimonNyvall

[Obsolete("Use this other one instead")] attribute

On Wed, Nov 22, 2023 at 6:04 AM Simon Nyvall @.***> wrote:

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?

— Reply to this email directly, view it on GitHub https://github.com/ardalis/GuardClauses/issues/309#issuecomment-1822557667, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAF66LZBDZBUY5N77TPPVN3YFXL4NAVCNFSM6AAAAAA7VJ6CGWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMRSGU2TONRWG4 . You are receiving this because you authored the thread.Message ID: @.***>

-- Steve Smith http://ardalis.com | http://twitter.com/ardalis

ardalis avatar Nov 22 '23 14:11 ardalis

@ardalis I think we can close this one. PR already merged!

canro91 avatar Jul 01 '24 18:07 canro91