ExpressionSyntaxExtensions Class
internal static class ExpressionSyntaxExtensionsNo documentation is available.
Methods
| Name | Description |
|---|---|
| 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
expressionExpressionSyntax
Returns
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
nodeSyntaxNode
Returns
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.