roslynator
roslynator copied to clipboard
Feature request: New analyzer and fix: Replace String.Compare(.......) == 0 with String.Equals
In some case the String.Compare where the result is checked for equality to zero could be replaced with String.Equals. At least the variants that take string, string:
String.Compare(a, b) == 0;
String.Equals(a, b, StringComparison.CurrentCulture);
And string, string, bool:
String.Compare(a, b, true) == 0;
String.Equals(a, b, StringComparison.CurrentCultureIgnoreCase);
I'm not really sure about the other overloads of String.Compare though.
It would be handy to have an analyzer that reports these cases and also a fix for these.
I guess we can extend this suggestion to have CompareOrdinal(a,b) == 0 replaced with Equals(a,b)
and also the non-static a.CompareTo(b) == 0 replaced with a.Equals(b, StringComparison. CurrentCulture)
Compare(string, string, StringComparison) == 0 seems also translatable to Equals(string, string, StringComparison)