コード例 #1
0
        public override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false);

            if (!TryFindFirstAncestorOrSelf(root, context.Span, out UsingDirectiveSyntax usingDirective))
            {
                return;
            }

            CodeAction codeAction = CodeAction.Create(
                "Inline alias expression",
                cancellationToken => AvoidUsageOfUsingAliasDirectiveRefactoring.RefactorAsync(context.Document, usingDirective, cancellationToken),
                GetEquivalenceKey(DiagnosticIdentifiers.AvoidUsageOfUsingAliasDirective));

            context.RegisterCodeFix(codeAction, context.Diagnostics);
        }
コード例 #2
0
        public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false);

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

            if (usingDirective == null)
            {
                return;
            }

            CodeAction codeAction = CodeAction.Create(
                "Inline alias expression",
                cancellationToken => AvoidUsageOfUsingAliasDirectiveRefactoring.RefactorAsync(context.Document, usingDirective, cancellationToken),
                DiagnosticIdentifiers.AvoidUsageOfUsingAliasDirective + EquivalenceKeySuffix);

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