Esempio n. 1
0
        private async Task <Document> CrunchPropertyAsync(SyntaxNode oldRoot, Document document, PropertyDeclarationSyntax property, CancellationToken cancellationToken)
        {
            var syntaxTree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);

            var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);

            // Get the property's backing field.
            var backingField = property.GetBackingField(semanticModel);

            // Call the Property Cruncher. The code refactoring happens here.
            var collapser = new PropertyCruncher(semanticModel, backingField, property);
            var newRoot   = collapser.Visit(oldRoot);

            // Update code with the refactored Root
            return(document.WithSyntaxRoot(newRoot));
        }