public override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            SyntaxNode root = await context.GetSyntaxRootAsync().ConfigureAwait(false);

            if (!TryFindFirstAncestorOrSelf(root, context.Span, out TypeSyntax type, findInsideTrivia: true))
            {
                return;
            }

            TypeSyntax nullableType = GetNullableType(type);

            CodeAction codeAction = CodeAction.Create(
                $"Simplify name '{type}'",
                ct => SimplifyNullableOfTRefactoring.RefactorAsync(context.Document, type, nullableType, ct),
                GetEquivalenceKey(DiagnosticIdentifiers.SimplifyNullableOfT));

            context.RegisterCodeFix(codeAction, context.Diagnostics);
        }
예제 #2
0
        public sealed override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            SyntaxNode root = await context.Document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);

            TypeSyntax type = root
                              .FindNode(context.Span, findInsideTrivia: true, getInnermostNodeForTie: true)?
                              .FirstAncestorOrSelf <TypeSyntax>();

            if (type == null)
            {
                return;
            }

            TypeSyntax nullableType = GetNullableType(type);

            CodeAction codeAction = CodeAction.Create(
                $"Simplify name '{type}'",
                cancellationToken => SimplifyNullableOfTRefactoring.RefactorAsync(context.Document, type, nullableType, cancellationToken),
                DiagnosticIdentifiers.SimplifyNullableOfT + EquivalenceKeySuffix);

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