Skip to content

Convert a "Not Any" query for a condition to a "All" query for the inverted condition #31

@moreirayokoyama

Description

@moreirayokoyama

Scenario 1: simple condition

This:

if (!results.Any(r => condition))
    throw new Exception("Error");

Becomes:

if (results.All(r => condition == false))
    throw new Exception("Error");

or

if (results.All(r => !condition))
    throw new Exception("Error");

Scenario 2: special case >, <, >= and <=

This:

if (!results.Any(r => r > 0))
    throw new Exception("Error");

Becomes:

if (results.All(r => r <= 0))
    throw new Exception("Error");

So it became more readable.
This is a refactoring, there is no diagnostic.

This is essentially a refactoring, so we are classifying it as a Hidden diagnostic.
Category is Refactoring.
Diagnostic id is: CC0043

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions