private static ExpressionSyntax AddParenthesesIfNecessary(SyntaxNode node, ExpressionSyntax expression) { if (!SyntaxUtility.AreParenthesesRedundantOrInvalid(node)) { expression = expression .WithoutTrivia() .Parenthesize(cutCopyTrivia: true); } return(expression); }
public static bool CanRefactor(RefactoringContext context, ExpressionSyntax expression) { if (!SyntaxUtility.AreParenthesesRedundantOrInvalid(expression)) { try { Refactor(expression, context.Root); return(true); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); Debug.Assert(false, $"{nameof(WrapExpressionInParenthesesRefactoring)}\r\n{expression.Kind().ToString()}"); } } return(false); }
private static async Task <ExpressionSyntax> ReplaceParameterExpressionWithArgumentExpressionAsync( ParameterInfo[] parameterInfos, InvocationExpressionSyntax invocation, ExpressionSyntax expression, Solution solution, CancellationToken cancellationToken) { ExpressionSyntax newExpression = await ReplaceParameterExpressionWithArgumentExpressionAsync(parameterInfos, expression, solution, cancellationToken).ConfigureAwait(false); if (!SyntaxUtility.AreParenthesesRedundantOrInvalid(invocation)) { newExpression = newExpression .WithoutTrivia() .Parenthesize(); } return(newExpression .WithTriviaFrom(invocation) .WithFormatterAnnotation()); }