private async Task <Document> ReplaceWithIsPattern(Document document, ExpressionSyntax expression, CancellationToken cancellationToken) { if (IfRecognizer.UsesEqualsForNullCheck(expression, out var otherIndentifer)) { var newSyntax = SyntaxFactory.IsPatternExpression(otherIndentifer, SyntaxFactory.ConstantPattern(SyntaxFactory.LiteralExpression(SyntaxKind.NullLiteralExpression)) ); var root = await document.GetSyntaxRootAsync(); return(document.WithSyntaxRoot(root.ReplaceNode(expression, newSyntax))); } return(document); }
private void AnalyzeOperation(OperationAnalysisContext context) { if (context.Operation is IConditionalOperation conditionalOperation && conditionalOperation.Condition != null) { if (conditionalOperation.Condition.Syntax is ExpressionSyntax expression && IfRecognizer.UsesEqualsForNullCheck(expression, out var otherIndentifer)) { var diagnostic = Diagnostic.Create(IsNullRule, expression.GetLocation(), otherIndentifer.Identifier.ValueText); context.ReportDiagnostic(diagnostic); } } }