private void AnalyzeQualifiedName(SyntaxNodeAnalysisContext context)
        {
            var qualifiedName = (QualifiedNameSyntax)context.Node;

            UsePredefinedTypeRefactoring.Analyze(context, qualifiedName);

            SimplifyNullableOfTRefactoring.Analyze(context, qualifiedName);
        }
        public override void Initialize(AnalysisContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            base.Initialize(context);

            context.RegisterSyntaxNodeAction(
                f => SimplifyNullableOfTRefactoring.AnalyzeGenericName(f),
                SyntaxKind.GenericName);
        }
        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);
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        private void AnalyzeIdentifierName(SyntaxNodeAnalysisContext context)
        {
            var genericName = (GenericNameSyntax)context.Node;

            SimplifyNullableOfTRefactoring.Analyze(context, genericName);
        }