Skip to content
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

AddParens only if it is not already a ParenthesizedExpressionSyntax #1151

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

LucTremblay
Copy link

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.

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.

1 participant