Exemple #1
0
        public override async Task RegisterCodeFixesAsync(CodeFixContext context)
        {
            var document = context.Document;
            var root     = await document.GetSyntaxRootAsync(context.CancellationToken).ConfigureAwait(false);

            var diagnostics = context.Diagnostics.Where(d => d.Id == AttributeIgnoreAnalyzer.DiagnosticId).ToArray();

            if (!diagnostics.Any())
            {
                return;
            }

            var attributeSyntax = root.FindNode(context.Span).FirstAncestorOrSelf <AttributeSyntax>();
            var mngr            = new IgnoreRelatedAttributeManager(attributeSyntax);

            context.RegisterCodeFix(
                CodeAction.Create(
                    title: Title,
                    createChangedDocument: c => MigrateAttribute(context.Document, root, mngr, c),
                    equivalenceKey: Title),
                diagnostics.First());
        }
        private void AnalyzeNode(SyntaxNodeAnalysisContext context)
        {
            var attributeSyntax = (AttributeSyntax)context.Node;
            var semanticModel   = context.SemanticModel;

            if (attributeSyntax.Name.ToString() != "Ignore" &&
                attributeSyntax.Name.ToString() != "TestCase" &&
                attributeSyntax.Name.ToString() != "TestFixture" &&
                attributeSyntax.Name.ToString() != "IgnoreAttribute" &&
                attributeSyntax.Name.ToString() != "TestCaseAttribute" &&
                attributeSyntax.Name.ToString() != "TestFixtureAttribute")
            {
                return;
            }

            var ignoreManager = new IgnoreRelatedAttributeManager(attributeSyntax);

            if (!ignoreManager.DoesIgnoringNeedAdjustment)
            {
                return;
            }

            context.ReportDiagnostic(Diagnostic.Create(Rule, attributeSyntax.GetLocation()));
        }
Exemple #3
0
        private Task <Document> MigrateAttribute(Document document, SyntaxNode root, IgnoreRelatedAttributeManager mngr, CancellationToken c)
        {
            var newRoot = root.ReplaceNode(mngr.Attribute, mngr.GetFixedAttribute());

            return(Task.FromResult(document.WithSyntaxRoot(newRoot)));
        }