예제 #1
0
        public static bool SkipSymbolAnalysisIgnoringAttributes(ISymbol symbol,
                                                                SettingsHandler settingsHandler)
        {
            var settings =
                settingsHandler.GetArnolyzerSettingsForProject(GetFilePathForSymbol(symbol));

            return(AutoGenerated(symbol) || IgnoredFile(symbol, settings));
        }
        private void AnalyzeSyntaxTree(SyntaxTreeAnalysisContext context)
        {
            var syntaxRoot = context.Tree.GetRoot(context.CancellationToken);
            var settings   = _settingsHandler.GetArnolyzerSettingsForProject(context.Tree.FilePath);

            var classDeclarations =
                syntaxRoot.DescendantNodes(DoNotDescendIntoTypeDeclarations)
                .Where(NodeIsPublicClassDeclaration)
                .Cast <ClassDeclarationSyntax>().ToList();

            var propertyDeclarations = from node in classDeclarations
                                       from property in
                                       node.DescendantNodes()
                                       .Where(NodeIsPropertyDeclaration)
                                       .Cast <PropertyDeclarationSyntax>()
                                       where SyntaxNodeIsPublic(property.Modifiers) &&
                                       !AutoGenerated(property) &&
                                       !IgnoredFile(property, settings) &&
                                       !PropertyHasIgnoreRuleAttribute(property, SuppressionAttributes)
                                       select new
            {
                className = node.Identifier.Text,
                property
            };

            foreach (var propertyDeclaration in propertyDeclarations)
            {
                propertyDeclaration.property.DescendantNodes()
                .Where(p => p.IsKind(SyntaxKind.SetAccessorDeclaration))
                .Cast <AccessorDeclarationSyntax>()
                .Where(s => s.Modifiers.Count == 0)
                .TryFirst()
                .Match()
                .Some()
                .Do(setter => context.ReportDiagnostic(
                        Diagnostic.Create(Rule,
                                          setter.Keyword.GetLocation(),
                                          propertyDeclaration.property.Identifier,
                                          propertyDeclaration.className)))
                .IgnoreElse()
                .Exec();
            }
        }