Esempio n. 1
0
        public override void ReportSuppressions(SuppressionAnalysisContext context)
        {
            foreach (var diagnostic in context.ReportedDiagnostics)
            {
                var root = diagnostic.Location.SourceTree.GetRoot(context.CancellationToken);
                if (root.FindNode(diagnostic.Location.SourceSpan) is { } node&&
                    node.TryFirstAncestorOrSelf(out IdentifierNameSyntax? identifierName) &&
                    context.GetSemanticModel(identifierName.SyntaxTree) is { } semanticModel)
                {
                    if (semanticModel.TryGetSymbol(identifierName, context.CancellationToken, out var symbol) &&
                        FieldOrProperty.TryCreate(symbol, out var fieldOrProperty) &&
                        fieldOrProperty.Type == KnownSymbols.DependencyPropertyKey)
                    {
                        context.ReportSuppression(Suppression.Create(Descriptor, diagnostic));
                    }

                    if (identifierName.Parent is MethodDeclarationSyntax method &&
                        ClrMethod.IsAttachedSet(method, semanticModel, context.CancellationToken, out _, out _))
                    {
                        context.ReportSuppression(Suppression.Create(Descriptor, diagnostic));
                    }
                }
            }
        }