ExpressionSyntaxExtensions Class

internal static class ExpressionSyntaxExtensions

No documentation is available.

Methods

NameDescription
Parenthesize(ExpressionSyntax)Wraps the expression in parentheses.
Parenthesize(SyntaxNode)Wraps the node in parentheses when it is an expression.

Parenthesize overloads

Parenthesize(ExpressionSyntax)

Wraps the expression in parentheses.

public static ExpressionSyntax Parenthesize(this ExpressionSyntax expression)
Parameters
expression ExpressionSyntax
Returns

ExpressionSyntax

Remarks

Generated code usually appends to an expression, either as the target of a member access or as an operand of a binary operator. Both bind tighter than most expressions, so an operand such as a ? b : c has to be parenthesized to preserve the meaning of the original code.

The trivia of the expression stays inside of the parentheses, so the trailing comment of a + b // comment ends up before the closing parenthesis.

When the project references a Roslyn workspaces package, the parentheses are annotated with Simplifier.Annotation, so a code fix removes the ones the final document doesn't need while post-processing it.

Parenthesize(SyntaxNode)

Wraps the node in parentheses when it is an expression.

public static SyntaxNode Parenthesize(this SyntaxNode node)
Parameters
node SyntaxNode
Returns

SyntaxNode

Remarks

Nodes that are not an ExpressionSyntax, such as a statement or a type declaration, cannot be parenthesized and are returned as-is. See ExpressionSyntaxExtensions.Parenthesize for the details of the generated parentheses.