SEC0012: String can be compared with .IsBeforeOrEqualTo()
Cause
The code contains an expression like string.Compare(a, b, comparison) <= 0
Rule description
Replace string.Compare(a, b, comparison) <= 0
with a.IsBeforeOrEqualTo(b, comparison)
How to fix violations
- Add a using declaration for the
Stravaig.Extensions.Core
namespace if it does not already exist. - Replace any instance of
string.Compare(a, b, comparison) <= 0
witha.IsBeforeOrEqualTo(b, comparison)
When to suppress warnings
If you prefer the original style of string check.
Example of a violation
if (string.Compare(a, b, StringComparison.OrdinalIgnoreCase) <= 0)
{
// Perform work required when a is before or equal to b.
}