Skip to content

AddParens only if it is not already a ParenthesizedExpressionSyntax #1151

New issue

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

Conversation

LucTremblay
Copy link
Contributor

Enhancement

#1146

Using the test RelationalOperatorsOnNullableTypeInConditionAsync for demonstration

During the debugging session:

For vb node (with nullable variable) at the begining of ConvertBinaryExpressionAsync method :
x = y

C# code at the end of the method:
Before:
ParenthesizedExpressionSyntax ParenthesizedExpression ((((((((x))).HasValue)&&((((y))).HasValue)))&&((((((x))).Value)==((((y))).Value)))))

After:
ParenthesizedExpressionSyntax ParenthesizedExpression ((((x).HasValue)&&((y).HasValue))&&(((x).Value)==((y).Value)))

Solution

In AddParens, only add parenthesis if it is not already a ParenthesizedExpressionSyntax
This eliminate a lot of unneeded parenthesis

This is a modification to the current AddParens method. It seems to have only one definition of such method. But the SyntaxFactory.ParenthesizedExpression is directly call at many place in the code.

@GrahamTheCoder GrahamTheCoder merged commit 950ee9b into icsharpcode:master Nov 9, 2024
2 checks passed
@LucTremblay LucTremblay deleted the addParensIfNotParenthesizedExpression branch November 9, 2024 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy