예제 #1
0
            protected override void AnalyzeSymbol(SymbolAnalysisContext context, ICodeAnalyzerDianosticReporter reporter)
            {
                IMethodSymbol method = context.Symbol as IMethodSymbol;

                if (method == null || !method.IsGenericMethod || !method.HasAttributeWithName(Consts.ScriptIgnoreGenericArgumentsAttribute))
                {
                    return;
                }

                var references    = method.DeclaringSyntaxReferences;
                var nodeReference = references.Single();
                MethodDeclarationSyntax methodDeclarationSyntax
                    = nodeReference.GetSyntax(context.CancellationToken) as MethodDeclarationSyntax;

                var syntaxTree    = methodDeclarationSyntax.SyntaxTree;
                var semanticModel = context.Compilation.GetSemanticModel(syntaxTree);

                if (methodDeclarationSyntax != null)
                {
                    GenericMethodInvocationSyntaxWalker walker = new GenericMethodInvocationSyntaxWalker(semanticModel);
                    walker.Visit(methodDeclarationSyntax);

                    foreach (var invocation in walker.FoundInvocations)
                    {
                        if (!invocation.HasScriptIgnoreGenericArgumentsAttribute)
                        {
                            reporter.Report(invocation.Node.GetLocation(), invocation.Name.TryGetInferredMemberName());
                        }
                    }
                }
            }
예제 #2
0
            protected override void AnalyzeCodeBlock(CodeBlockAnalysisContext context, ICodeAnalyzerDianosticReporter reporter)
            {
                GenericMethodInvocationSyntaxWalker missingTypeArgumentSyntaxWalker = new GenericMethodInvocationSyntaxWalker(context.SemanticModel);

                missingTypeArgumentSyntaxWalker.Visit(context.CodeBlock);

                foreach (var invocation in missingTypeArgumentSyntaxWalker.FoundInvocations)
                {
                    if (!(invocation.Name is GenericNameSyntax) && !invocation.HasScriptIgnoreGenericArgumentsAttribute)
                    {
                        reporter.Report(invocation.Node.GetLocation(), invocation.Name.TryGetInferredMemberName());
                    }
                }
            }