csharp:S2219 Generates false-positive on pattern-matching with `is` operator on strings

Hello there. I’m using SonarQube Developer Edition Version 8.3.1 (build 34397) testing C# solution and I get Code Smells on lines of code that compare two string-typed objects (class property and string constant on a static class) using pattern matching of is operator:

bool result = myObject.StringProperty is Const.Example;

instead of:

bool result = myObject.StringProperty == Const.Example;

No type-check is necessary because both types are known to be the same during compile time, but the rule still complains with “Use a ‘null’ check instead.”

Hi @MKenin,

I can confirm this as False Positive. I’ve added this issue to track it.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.