Skip to content

Gendarme.Rules.Globalization.PreferStringComparisonOverrideRule(git)

Sebastien Pouliot edited this page Mar 2, 2011 · 1 revision

PreferStringComparisonOverrideRule

Assembly: Gendarme.Rules.Globalization
Version: git

Description

This rule detects calls to method that could be changed to call an override accepting an extra System.StringComparison parameter. Using the override makes the code easier to maintain since it makes the intent clear on how the string needs to be compared. It is even more important since the default string comparison rules have changed between .NET 2.0 and .NET 4.0.

Examples

Bad example:

public bool Check (string name)
{
    // it's not clear if the string comparison should be culture sensitive or not
    return (String.Compare (name, "Software") == 0);
}

Good example:

public bool Check (string name)
{
    return (String.Compare (name, "Software", StringComparison.CurrentCulture) == 0);
}

Source code

You can browse the latest source code of this rule on github.com

Clone this wiki locally