private async Task <Document> ConvertToDateTimeOffsetTypeAsync(Document document, MethodDeclarationSyntax localDeclaration, CancellationToken cancellationToken) { SyntaxNode finalResultSyntaxNode = DateTimeOffSetHelper.FixCode(localDeclaration); var newLocalDecl = finalResultSyntaxNode.WithAdditionalAnnotations(Formatter.Annotation); var oldRoot = await document.GetSyntaxRootAsync(cancellationToken); var newRoot = oldRoot.ReplaceNode(localDeclaration, newLocalDecl); return(document.WithSyntaxRoot(newRoot)); }
private async Task <Document> ConvertToDateTimeOffsetTypeAsync(Document document, LocalDeclarationStatementSyntax localDeclaration, CancellationToken cancellationToken) { // #1 Replace DateTime x = new DateTime(); // #2 Replace DateTime x = DateTime.Now; // #3 var x = DateTime.Now; // #4 var x = new DateTime(); // #5 var x = new DateTime(); // #6 var x = new DateTime(); var firstToken = localDeclaration.GetFirstToken(); var leadingTrivia = firstToken.LeadingTrivia; var trimmedLocal = localDeclaration.ReplaceToken( firstToken, firstToken.WithLeadingTrivia(SyntaxTriviaList.Empty)); SyntaxNode finalResultSyntaxNode = DateTimeOffSetHelper.FixCode(localDeclaration); var newLocalDecl = finalResultSyntaxNode.WithAdditionalAnnotations(Formatter.Annotation); var oldRoot = await document.GetSyntaxRootAsync(cancellationToken); var newRoot = oldRoot.ReplaceNode(localDeclaration, newLocalDecl); return(document.WithSyntaxRoot(newRoot)); }