Fix S6605 FP: Should not fire in expressions #7508
Labels
Area: C#
C# rules related issues.
Area: VB.NET
VB.NET rules related issues.
Type: False Positive
Rule IS triggered when it shouldn't be.
Milestone
Description
As I understand, rule S6605 suggests the use of the collection-specific "Exists" method for performance reasons. It becomes a problem when the "Any" extension method is used in an expression because switching to the "Exists" method changes the expression (e. g. the C# MongoDb Driver supports Any but not Exists). There are also no performance benefits unless the expression is compiled and executed which should not be done anyways when performance is important.
Repro steps
Expression<Func<List<int>, bool>> containsThree = list => list.Any(el => el == 3);
Expected behavior
The rule should not fire.
Actual behavior
The rule fires.
Related information
The text was updated successfully, but these errors were encountered: