We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The expression !a.Equals(b) is converted to !a == b, which is invalid C#. The suggested replacement should be a != b.
!a.Equals(b)
!a == b
a != b
Test case to repro:
[Test] public void DiagnoseAndFixNegatedStringEquals() { const string program = @"using System; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { GC.KeepAlive(!""a"".Equals(""b"")); } } } "; var expected = new DiagnosticResult { Id = OverloadWithStringComparisonAnalyzer.AvoidStringEqualsDiagnosticId, Message = "Use operator== or a non-ordinal StringComparison.", Severity = DiagnosticSeverity.Warning, Locations = new[] { new DiagnosticResultLocation("Test0.cs", 8, 22) }, }; VerifyCSharpDiagnostic(program, expected); const string fix1 = @"using System; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { GC.KeepAlive(""a"" != ""b""); } } } "; VerifyCSharpFix(program, fix1, 0); const string fix2 = @"using System; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { GC.KeepAlive(!""a"".Equals(""b"", StringComparison.OrdinalIgnoreCase)); } } } "; VerifyCSharpFix(program, fix2, 1); }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The expression
!a.Equals(b)
is converted to!a == b
, which is invalid C#. The suggested replacement should bea != b
.Test case to repro:
The text was updated successfully, but these errors were encountered: