public AnalysisContext(CSharpExplodedGraph explodedGraph) { nullPointerCheck = new NullValueAccessedCheck(explodedGraph); nullPointerCheck.ValuePropertyAccessed += AddIdentifier; explodedGraph.AddExplodedGraphCheck(nullPointerCheck); }
private static void CheckEmptyNullableAccess(ExplodedGraph explodedGraph, SyntaxNodeAnalysisContext context) { var nullPointerCheck = new NullValueAccessedCheck(explodedGraph); explodedGraph.AddExplodedGraphCheck(nullPointerCheck); var nullIdentifiers = new HashSet <IdentifierNameSyntax>(); EventHandler <MemberAccessedEventArgs> nullValueAccessedHandler = (sender, args) => nullIdentifiers.Add(args.Identifier); nullPointerCheck.ValuePropertyAccessed += nullValueAccessedHandler; try { explodedGraph.Walk(); } finally { nullPointerCheck.ValuePropertyAccessed -= nullValueAccessedHandler; } foreach (var nullIdentifier in nullIdentifiers) { context.ReportDiagnostic(Diagnostic.Create(rule, nullIdentifier.Parent.GetLocation(), nullIdentifier.Identifier.ValueText)); } }
private static void CheckEmptyNullableAccess(ExplodedGraph explodedGraph, SyntaxNodeAnalysisContext context) { var nullPointerCheck = new NullValueAccessedCheck(explodedGraph); explodedGraph.AddExplodedGraphCheck(nullPointerCheck); var nullIdentifiers = new HashSet<IdentifierNameSyntax>(); EventHandler<MemberAccessedEventArgs> nullValueAccessedHandler = (sender, args) => nullIdentifiers.Add(args.Identifier); nullPointerCheck.ValuePropertyAccessed += nullValueAccessedHandler; try { explodedGraph.Walk(); } finally { nullPointerCheck.ValuePropertyAccessed -= nullValueAccessedHandler; } foreach (var nullIdentifier in nullIdentifiers) { context.ReportDiagnostic(Diagnostic.Create(Rule, nullIdentifier.Parent.GetLocation(), nullIdentifier.Identifier.ValueText)); } }