public static async Task ComputeRefactoringAsync(RefactoringContext context, EventFieldDeclarationSyntax eventFieldDeclaration)
        {
            if (!eventFieldDeclaration.HasDocumentationComment())
            {
                SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

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

                if (data.Success)
                {
                    RegisterRefactoring(context, eventFieldDeclaration, data);
                }
            }
        }
예제 #2
0
        public override SyntaxNode VisitEventFieldDeclaration(EventFieldDeclarationSyntax node)
        {
            bool isPubliclyVisible = IsPubliclyVisible(node);

            node = (EventFieldDeclarationSyntax)base.VisitEventFieldDeclaration(node);

            if (isPubliclyVisible &&
                !node.HasDocumentationComment())
            {
                return(AddDocumentationComment(node));
            }
            else
            {
                return(node);
            }
        }
예제 #3
0
        public static async Task ComputeRefactoringsAsync(RefactoringContext context, EventFieldDeclarationSyntax eventFieldDeclaration)
        {
            if (context.IsRefactoringEnabled(RefactoringDescriptors.GenerateEventInvokingMethod))
            {
                await GenerateOnEventMethodRefactoring.ComputeRefactoringAsync(context, eventFieldDeclaration).ConfigureAwait(false);
            }

            if (context.IsRefactoringEnabled(RefactoringDescriptors.ExpandEventDeclaration) &&
                eventFieldDeclaration.Span.Contains(context.Span) &&
                ExpandEventDeclarationRefactoring.CanRefactor(eventFieldDeclaration))
            {
                context.RegisterRefactoring(
                    "Expand event",
                    ct => ExpandEventDeclarationRefactoring.RefactorAsync(context.Document, eventFieldDeclaration, ct),
                    RefactoringDescriptors.ExpandEventDeclaration);
            }

            if (context.IsRefactoringEnabled(RefactoringDescriptors.CopyDocumentationCommentFromBaseMember) &&
                eventFieldDeclaration.Span.Contains(context.Span) &&
                !eventFieldDeclaration.HasDocumentationComment())
            {
                SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                CopyDocumentationCommentFromBaseMemberRefactoring.ComputeRefactoring(context, eventFieldDeclaration, semanticModel);
            }

            if (context.IsRefactoringEnabled(RefactoringDescriptors.AddMemberToInterface))
            {
                VariableDeclaratorSyntax variableDeclarator = eventFieldDeclaration.Declaration?.Variables.SingleOrDefault(shouldThrow: false);

                if (variableDeclarator != null &&
                    context.Span.IsEmptyAndContainedInSpanOrBetweenSpans(variableDeclarator.Identifier))
                {
                    SemanticModel semanticModel = await context.GetSemanticModelAsync().ConfigureAwait(false);

                    AddMemberToInterfaceRefactoring.ComputeRefactoring(context, eventFieldDeclaration, semanticModel);
                }
            }
        }