Skip to content

[Analyzer] string.ToLower() == otherString.ToLower()Β #78607

@stephentoub

Description

@stephentoub

The right way to compare two strings in a case-insensitive manner is via a StringComparer/Comparison that specifies case-insensitivity. But there's are many cases where code is using ToLower() on each string and then comparing those for equality, e.g.

We should write an analyzer that flags such uses and recommends fixing them to use Equals with the appropriate comparison.

This analyzer should cover ToUpper too even if the usage is low for that.

Such analyzers will help avoid the allocations caused by ToLower/ToUpper calls.

Performance rules Category
Severity = suggestion

Metadata

Metadata

Assignees

Labels

api-approvedAPI was approved in API review, it can be implementedarea-System.Globalizationcode-analyzerMarks an issue that suggests a Roslyn analyzercode-fixerMarks an issue that suggests a Roslyn code fixerhelp wanted[up-for-grabs] Good issue for external contributorspartner-impactThis issue impacts a partner who needs to be kept updated

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions