New Analyzer to avoid StringComparison #31059
Labels
closed-out-of-scope
This is not something that will be fixed/implemented and the issue is closed.
customer-reported
When using DbSet.Where(x => x.Equals(y)), then the dotnet recommended rules give a warning that you should have the code implement a String Case Comparison, such as: DbSet.Where(x => x.Equals(y, StringComparison.OrdinalIgnoreCase))
When you TreatWarningsAsErrors, like my company, you're left with disabling the pragma, or, using the == comparator.
However, our company has historically required you compare strings with .Equals, instead of == based on our coding conventions.
The problem is, if we're comparing 2 values that are strings, we shouldn't find out at runtime that a problem occurs if we include OrdinalIgnoreCase. It would be far better to find out at development time.
I'd like to see an analyzer that requires that you use == instead of .Equals if your delegate within the Linq statement compares string values. Or, if it's possible to counteract CA1309, then a rule that counteracts it if you're within that statement.
The text was updated successfully, but these errors were encountered: