Пример #1
0
        private void AnalyzeObjectCreationExpression(SyntaxNodeAnalysisContext context)
        {
            var objectCreationExpression = (ObjectCreationExpressionSyntax)context.Node;

            RemoveEmptyInitializerRefactoring.Analyze(context, objectCreationExpression);

            AddConstructorArgumentListRefactoring.Analyze(context, objectCreationExpression);

            RemoveEmptyArgumentListRefactoring.Analyze(context, objectCreationExpression);
        }
        public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false);

            if (!TryFindFirstAncestorOrSelf(root, context.Span, out ArgumentListSyntax argumentList))
            {
                return;
            }

            CodeAction codeAction = CodeAction.Create(
                "Remove empty argument list",
                cancellationToken => RemoveEmptyArgumentListRefactoring.RefactorAsync(context.Document, argumentList, cancellationToken),
                GetEquivalenceKey(DiagnosticIdentifiers.RemoveEmptyArgumentList));

            context.RegisterCodeFix(codeAction, context.Diagnostics);
        }
Пример #3
0
        public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false);

            ArgumentListSyntax argumentList = root
                                              .FindNode(context.Span, getInnermostNodeForTie: true)?
                                              .FirstAncestorOrSelf <ArgumentListSyntax>();

            if (argumentList == null)
            {
                return;
            }

            CodeAction codeAction = CodeAction.Create(
                "Remove empty argument list",
                cancellationToken => RemoveEmptyArgumentListRefactoring.RefactorAsync(context.Document, argumentList, cancellationToken),
                DiagnosticIdentifiers.RemoveEmptyArgumentList + EquivalenceKeySuffix);

            context.RegisterCodeFix(codeAction, context.Diagnostics);
        }