Esempio n. 1
0
        public static async Task <Document> RefactorAsync(
            Document document,
            MemberDeclarationSyntax memberDeclaration,
            bool copyCommentFromBaseIfAvailable,
            CancellationToken cancellationToken)
        {
            MemberDeclarationSyntax newNode = null;

            if (copyCommentFromBaseIfAvailable &&
                DocumentationCommentGenerator.CanGenerateFromBase(memberDeclaration.Kind()))
            {
                SemanticModel semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false);

                BaseDocumentationCommentData data = DocumentationCommentGenerator.GenerateFromBase(memberDeclaration, semanticModel, cancellationToken);

                if (data.Success)
                {
                    newNode = memberDeclaration.WithDocumentationComment(data.Comment, indent: true);
                }
            }

            newNode = newNode ?? memberDeclaration.WithNewSingleLineDocumentationComment();

            return(await document.ReplaceNodeAsync(memberDeclaration, newNode, cancellationToken).ConfigureAwait(false));
        }
        public static async Task ComputeRefactoringAsync(RefactoringContext context, ConstructorDeclarationSyntax constructorDeclaration)
        {
            if (!constructorDeclaration.HasDocumentationComment())
            {
                SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                BaseDocumentationCommentData data = DocumentationCommentGenerator.GenerateFromBase(constructorDeclaration, semanticModel, context.CancellationToken);

                if (data.Success)
                {
                    RegisterRefactoring(context, constructorDeclaration, data);
                }
            }
        }
 private static void RegisterRefactoring(RefactoringContext context, MemberDeclarationSyntax memberDeclaration, BaseDocumentationCommentData data)
 {
     context.RegisterRefactoring(
         GetTitle(memberDeclaration, data.Origin),
         cancellationToken => RefactorAsync(context.Document, memberDeclaration, data.Comment, cancellationToken));
 }