private static void CheckForNullDereference(CSharpExplodedGraph explodedGraph, SyntaxNodeAnalysisContext context) { var methodSymbol = context.SemanticModel.GetSymbolInfo(context.Node).Symbol ?? context.SemanticModel.GetDeclaredSymbol(context.Node); if (!methodSymbol.IsPubliclyAccessible()) { return; } var nullPointerCheck = new NullPointerDereference.NullPointerCheck(explodedGraph); explodedGraph.AddExplodedGraphCheck(nullPointerCheck); var identifiers = new HashSet <IdentifierNameSyntax>(); void memberAccessingHandler(object sender, MemberAccessingEventArgs args) => CollectMemberAccesses(args, identifiers, context.SemanticModel); nullPointerCheck.MemberAccessing += memberAccessingHandler; try { explodedGraph.Walk(); } finally { nullPointerCheck.MemberAccessing -= memberAccessingHandler; } foreach (var identifier in identifiers) { context.ReportDiagnosticWhenActive(Diagnostic.Create(rule, identifier.GetLocation(), identifier.Identifier.ValueText)); } }
public AnalysisContext(CSharpExplodedGraph explodedGraph, SyntaxNodeAnalysisContext context) { if (!GetMethodSymbol(context).IsPubliclyAccessible()) { return; } syntaxNodeAnalysisContext = context; nullPointerCheck = explodedGraph.NullPointerCheck; nullPointerCheck.MemberAccessing += MemberAccessingHandler; }
public AnalysisContext(CSharpExplodedGraph explodedGraph, SyntaxNodeAnalysisContext context) { if (!GetMethodSymbol(context).IsPubliclyAccessible()) { return; } this.syntaxNodeAnalysisContext = context; this.nullPointerCheck = new NullPointerDereference.NullPointerCheck(explodedGraph); this.nullPointerCheck.MemberAccessing += MemberAccessingHandler; explodedGraph.AddExplodedGraphCheck(this.nullPointerCheck); }