private static bool IsConst(SyntaxNode syntax, SyntaxNodeAnalysisContext context)
        {
            switch (syntax)
            {
            case IdentifierNameSyntax i:
            {
                var type    = context.FindContainingType();
                var isConst = type.GetMembers(i.GetName()).OfType <IFieldSymbol>().Any(_ => _.IsConst);

                return(isConst);
            }

            case MemberAccessExpressionSyntax m when m.IsKind(SyntaxKind.SimpleMemberAccessExpression):
            {
                var type = m.GetTypeSymbol(context.SemanticModel);

                // only get the real enum members, no local variables or something
                return(type?.IsEnum() is true);
            }

            default:
            {
                return(false);
            }
            }
        }
Exemple #2
0
        private static bool ShallAnalyze(SyntaxNodeAnalysisContext context)
        {
            var type = context.FindContainingType();

            if (type is null)
            {
                return(false);
            }

            if (type.IsTestClass())
            {
                return(true);
            }

            var assemblyName = type.ContainingAssembly.Name;

            if (assemblyName.Contains("Test"))
            {
                return(!assemblyName.Contains("MiKoSolutions.Analyzers"));
            }

            return(false);
        }