private static async Task <Document> ReplaceWithExpressionBodiedMember(Document document, ConversionOperatorDeclarationSyntax declaration, CancellationToken cancellationToken) { SyntaxTriviaList leadingTrivia; var expression = GetExpressionAndLeadingTrivia(declaration.Body, out leadingTrivia); var declarationTrivia = declaration.GetLeadingTrivia(); declarationTrivia = declarationTrivia.AddRange(leadingTrivia); var newDeclaration = declaration .WithLeadingTrivia(declarationTrivia) .WithExpressionBody(SyntaxFactory.ArrowExpressionClause(expression)) .WithBody(null) .WithSemicolonToken(GetSemicolon(declaration.Body)) .WithAdditionalAnnotations(Formatter.Annotation); var root = await document.GetSyntaxRootAsync(cancellationToken); var newRoot = root.ReplaceNode(declaration, newDeclaration); return(document.WithSyntaxRoot(newRoot)); }
private static async Task<Document> ReplaceWithExpressionBodiedMember(Document document, ConversionOperatorDeclarationSyntax declaration, CancellationToken cancellationToken) { SyntaxTriviaList leadingTrivia; var expression = GetExpressionAndLeadingTrivia(declaration.Body, out leadingTrivia); var declarationTrivia = declaration.GetLeadingTrivia(); declarationTrivia = declarationTrivia.AddRange(leadingTrivia); var newDeclaration = declaration .WithLeadingTrivia(declarationTrivia) .WithExpressionBody(SyntaxFactory.ArrowExpressionClause(expression)) .WithBody(null) .WithSemicolonToken(GetSemicolon(declaration.Body)) .WithAdditionalAnnotations(Formatter.Annotation); var root = await document.GetSyntaxRootAsync(cancellationToken); var newRoot = root.ReplaceNode(declaration, newDeclaration); return document.WithSyntaxRoot(newRoot); }