public override void Initialize(AnalysisContext analysisContext) #pragma warning restore RS1026 // Enable concurrent execution { // TODO: Make analyzer thread-safe. //analysisContext.EnableConcurrentExecution(); // Security analyzer - analyze and report diagnostics in generated code. analysisContext.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics); analysisContext.RegisterCompilationStartAction( (context) => { Compilation compilation = context.Compilation; var xmlTypes = new CompilationSecurityTypes(compilation); if (ReferencesAnyTargetType(xmlTypes)) { Version version = SecurityDiagnosticHelpers.GetDotNetFrameworkVersion(compilation); // bail if we are not analyzing project targeting .NET Framework // TODO: should we throw an exception to notify user? if (version != null) { SymbolAndNodeAnalyzer analyzer = GetAnalyzer(context, xmlTypes, version); context.RegisterSymbolAction(analyzer.AnalyzeSymbol, SymbolKind.NamedType); } } }); }
protected override SymbolAndNodeAnalyzer GetAnalyzer(CompilationStartAnalysisContext context, CompilationSecurityTypes types, Version targetFrameworkVersion) { SymbolAndNodeAnalyzer analyzer = new SymbolAndNodeAnalyzer(types, CSharpSyntaxNodeHelper.Default, targetFrameworkVersion); context.RegisterSyntaxNodeAction(analyzer.AnalyzeNode, SyntaxKind.MethodDeclaration, SyntaxKind.ConstructorDeclaration); return analyzer; }
public override void Initialize(AnalysisContext context) { context.EnableConcurrentExecution(); // Security analyzer - analyze and report diagnostics in generated code. context.ConfigureGeneratedCodeAnalysis( GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics); context.RegisterCompilationStartAction(context => { Compilation compilation = context.Compilation; var xmlTypes = new CompilationSecurityTypes(compilation); if (ReferencesAnyTargetType(xmlTypes)) { var version = SecurityDiagnosticHelpers.GetDotNetFrameworkVersion(compilation); // bail if we are not analyzing project targeting .NET Framework // TODO: should we throw an exception to notify user? if (version != null) { SymbolAndNodeAnalyzer analyzer = new SymbolAndNodeAnalyzer(xmlTypes, version); context.RegisterSymbolAction(analyzer.AnalyzeSymbol, SymbolKind.NamedType); context.RegisterOperationBlockStartAction(analyzer.AnalyzeOperationBlock); } } }); }
protected override SymbolAndNodeAnalyzer GetAnalyzer(CompilationStartAnalysisContext context, CompilationSecurityTypes types, Version targetFrameworkVersion) { SymbolAndNodeAnalyzer analyzer = new SymbolAndNodeAnalyzer(types, CSharpSyntaxNodeHelper.Default, targetFrameworkVersion); context.RegisterSyntaxNodeAction(analyzer.AnalyzeNode, SyntaxKind.MethodDeclaration, SyntaxKind.ConstructorDeclaration); return(analyzer); }
public override void Initialize(AnalysisContext analysisContext) { analysisContext.RegisterCompilationStartAction( (context) => { Compilation compilation = context.Compilation; var xmlTypes = new CompilationSecurityTypes(compilation); if (ReferencesAnyTargetType(xmlTypes)) { Version version = SecurityDiagnosticHelpers.GetDotNetFrameworkVersion(compilation); // bail if we are not analyzing project targeting .NET Framework // TODO: should we throw an exception to notify user? if (version != null) { SymbolAndNodeAnalyzer analyzer = GetAnalyzer(context, xmlTypes, version); context.RegisterSymbolAction(analyzer.AnalyzeSymbol, SymbolKind.NamedType); } } }); }