Vincent Vincent - 1 year ago 92
C# Question

Is CA1309 still valid for source compiled against .NET 4.5.1?

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:

enter image description here
When looking at the reference source for
here, it shows that the
operator ==
which in turn uses
. When calling the
overload proposed by CA1309, the same
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
nuget package to run code analysis on-the-fly.

Answer Source

Not much of an answer but, per request of cynic from the comments, an issue has been raised over at the roslyn github. As soon as the issue has been resolved, this answer will be updated. For now, we wait.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download