Skip to content

Fix AgainstExpression to be Expression #309

@ardalis

Description

@ardalis

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions