GuardClauses
GuardClauses copied to clipboard
Fix `AgainstExpression` to be `Expression`
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:
- Mark
AgainstExpressionas obsolete. - Create
Expressionor name similar if we can't use that name and have it do the same thing. - Consider using CallerArgumentExpression in the parameter list if that makes sense.
- 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.
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?
[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 I think we can close this one. PR already merged!