private static Task <Document> CallAnyInsteadOfUsingCountAsync( Document document, BinaryExpressionSyntax binaryExpression, CancellationToken cancellationToken) { BinaryExpressionInfo binaryExpressionInfo = SyntaxInfo.BinaryExpressionInfo(binaryExpression); if (!(binaryExpressionInfo.Left is MemberAccessExpressionSyntax memberAccessExpression)) { memberAccessExpression = (MemberAccessExpressionSyntax)binaryExpressionInfo.Right; } SimpleNameSyntax name = memberAccessExpression.Name; ExpressionSyntax newExpression = SimpleMemberInvocationExpression( memberAccessExpression.Expression, IdentifierName("Any").WithLeadingTrivia(name.GetLeadingTrivia()), ArgumentList().WithTrailingTrivia(name.GetTrailingTrivia())); if (binaryExpression.IsKind(SyntaxKind.EqualsExpression)) { newExpression = LogicalNotExpression(newExpression.WithoutLeadingTrivia().Parenthesize()); } newExpression = newExpression .WithTriviaFrom(binaryExpression) .WithFormatterAnnotation(); return(document.ReplaceNodeAsync(binaryExpression, newExpression, cancellationToken)); }
private static SimpleNameSyntax ChangeName(SimpleNameSyntax simpleName, string newName) { return(simpleName.WithIdentifier( Identifier( simpleName.GetLeadingTrivia(), newName, simpleName.GetTrailingTrivia()))); }