예제 #1
0
 protected override void Initialize(ParameterLoadingAnalysisContext context)
 {
     context.RegisterSyntaxNodeActionInNonGenerated(
         c =>
     {
         var declaration = (InterfaceStatementSyntax)c.Node;
         if (!FieldNameChecker.IsRegexMatch(declaration.Identifier.ValueText, Pattern))
         {
             c.ReportDiagnostic(Diagnostic.Create(Rule, declaration.Identifier.GetLocation(), Pattern));
         }
     },
         SyntaxKind.InterfaceStatement);
 }
예제 #2
0
 protected override void Initialize(ParameterLoadingAnalysisContext context)
 {
     context.RegisterSyntaxNodeActionInNonGenerated(
         c =>
     {
         var declaration     = (NamespaceStatementSyntax)c.Node;
         var declarationName = declaration.Name?.ToString();
         if (declarationName != null &&
             !FieldNameChecker.IsRegexMatch(declarationName, Pattern))
         {
             c.ReportDiagnostic(Diagnostic.Create(Rule, declaration.Name.GetLocation(), Pattern));
         }
     },
         SyntaxKind.NamespaceStatement);
 }
예제 #3
0
        private void ProcessLoop <T>(T loop, Func <T, VisualBasicSyntaxNode> GetControlVariable, Func <ILocalSymbol, bool> isDeclaredInLoop,
                                     SyntaxNodeAnalysisContext context)
        {
            var controlVar = GetControlVariable(loop);

            if (!(controlVar is IdentifierNameSyntax))
            {
                return;
            }

            var symbol = context.SemanticModel.GetSymbolInfo(controlVar).Symbol as ILocalSymbol;

            if (symbol == null ||
                !isDeclaredInLoop(symbol) ||
                FieldNameChecker.IsRegexMatch(symbol.Name, Pattern))
            {
                return;
            }

            context.ReportDiagnostic(Diagnostic.Create(Rule, controlVar.GetLocation(), Pattern));
        }
예제 #4
0
        private void ProcessVariableDeclarator(SyntaxNodeAnalysisContext context)
        {
            var declarator = (VariableDeclaratorSyntax)context.Node;

            if (declarator.Parent is FieldDeclarationSyntax)
            {
                return;
            }

            foreach (var name in declarator.Names
                     .Where(n => n != null &&
                            !FieldNameChecker.IsRegexMatch(n.Identifier.ValueText, Pattern)))
            {
                var symbol = context.SemanticModel.GetDeclaredSymbol(name) as ILocalSymbol;
                if (symbol == null ||
                    symbol.IsConst)
                {
                    continue;
                }

                context.ReportDiagnostic(Diagnostic.Create(Rule, name.Identifier.GetLocation(), Pattern));
            }
        }