src/extensions/default/analyzers/Microsoft.DotNet.UpgradeAssistant.Extensions.Default.CodeFixes/IdentifierUpgradeCodeFixer.cs
/// <summary>
/// Replaces a syntax node with a new fully qualified name or member accession expression from a given string.
/// </summary>
/// <param name="document">The document to update.</param>
/// <param name="node">The syntax node to be replaced.</param>
/// <param name="newIdentifier">A string representation of the new identifier (name of member access expression) to be used in the document.</param>
/// <param name="cancellationToken">A cancellation token.</param>
/// <returns>An updated document with the given node replaced with the new identifier.</returns>
Replaces a syntax node with a new fully qualified name or member accession expression from a given string.
Replaces a syntax node with a new fully qualified name or member accession expression from a given string .
private static async Task<Document> UpdateIdentifierTypeAsync(Document document, SyntaxNode node, string newIdentifier, CancellationToken cancellationToken)
        {
            var editor = await DocumentEditor.CreateAsync(document, cancellationToken).ConfigureAwait(false);
            var updatedNode = GetUpdatedNode(node, editor.Generator, newIdentifier)
                .WithAdditionalAnnotations(Simplifier.Annotation, Simplifier.AddImportsAnnotation)
                .WithTriviaFrom(node);
            editor.ReplaceNode(node, updatedNode);
            var updatedDocument = editor.GetChangedDocument();
            updatedDocument = await ImportAdder.AddImportsAsync(updatedDocument, Simplifier.AddImportsAnnotation, null, cancellationToken).ConfigureAwait(false);
            updatedDocument = await Simplifier.ReduceAsync(updatedDocument, Simplifier.Annotation, null, cancellationToken).ConfigureAwait(false);
            return updatedDocument;
        }
private static async Task < Document > UpdateIdentifierTypeAsync ( Document document , SyntaxNode node , string newIdentifier , CancellationToken cancellationToken ) { var editor = await DocumentEditor . CreateAsync ( document , cancellationToken ) . ConfigureAwait ( false ) ; var updatedNode = GetUpdatedNode ( node , editor . Generator , newIdentifier ) . WithAdditionalAnnotations ( Simplifier . Annotation , Simplifier . AddImportsAnnotation ) . WithTriviaFrom ( node ) ; editor . ReplaceNode ( node , updatedNode ) ; var updatedDocument = editor . GetChangedDocument ( ) ; updatedDocument = await ImportAdder . AddImportsAsync ( updatedDocument , Simplifier . AddImportsAnnotation , null , cancellationToken ) . ConfigureAwait ( false ) ; updatedDocument = await Simplifier . ReduceAsync ( updatedDocument , Simplifier . Annotation , null , cancellationToken ) . ConfigureAwait ( false ) ; return updatedDocument ; }
Replaces a syntax node with a new fully qualified name or member accession expression from a given string.
Replaces a syntax node with a new fully qualified name or member accession expression from a given string .
// Create new identifier // Add using declaration if needed // Simplify the call, if possible
An updated document with the given node replaced with the new identifier.
An updated document with the given node replaced with the new identifier .
document
Document
The document to update.
The document to update .
node
SyntaxNode
The syntax node to be replaced.
The syntax node to be replaced .
newIdentifier
string
A string representation of the new identifier (name of member access expression) to be used in the document.
A string representation of the new identifier ( name of member access expression ) to be used in the document .
cancellationToken
CancellationToken
A cancellation token.
A cancellation token .