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()); } } } }
protected virtual void AnalyzeSymbol(SymbolAnalysisContext context, ICodeAnalyzerDianosticReporter reporter) { }
protected virtual void AnalyzeCodeBlock(CodeBlockAnalysisContext context, ICodeAnalyzerDianosticReporter reporter) { }
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()); } } }