When we enabled fxcop with a superset of the "Microsoft All Rules" ruleset for one of our projects it also enabled CA1309 and immediately started complaining about constructions such as this:
if (translationItem.Description == "Description")
Showing warnings such as:
When looking at the reference source for
string
here, it shows that the operator ==
uses String.Equals
which in turn uses EqualsHelper
. When calling the Equals
overload proposed by CA1309, the same EqualsHelper
is called. Hence, it seems like the ==
operator already uses Ordinal comparison.
So my question is, should we refactor the snippet above into this:
if (string.Equals(translationItem.Description, "Description", StringComparison.Ordinal))
And if so, why should we?
P.S. We do really intend to use a case-sensitive string compare in the above snippets.
P.S.2. We use the Microsoft.CodeAnalysis.FxCopAnalyzers
nuget package to run code analysis on-the-fly.
Not much of an answer but, per request of cynic from the comments, an issue has been raised over at the roslyn github. The issue has been resolved and closed and the fix will be released with milestone 15.3.