public override void Initialize(AnalysisContext analysisContext)
        {
            analysisContext.RegisterCompilationStartAction(
                context =>
            {
                Compilation compilation = context.Compilation;
                var xmlTypes            = new XxeSecurityTypes(compilation);

                if (!xmlTypes.IsAnyTypeReferenced())
                {
                    return;
                }

                Version version = compilation.GetDotNetFrameworkVersion();
                if (version == null)
                {
                    return;
                }

                context.RegisterCodeBlockStartAction <CSharp.SyntaxKind>(
                    c =>
                {
                    var analyzer = new XxeAnalyzerCSharp(xmlTypes, version);
                    analyzer.RegisterSyntaxNodeAction(c);
                    c.RegisterCodeBlockEndAction(analyzer.AnalyzeCodeBlockEnd);
                });
            });
        }
Exemple #2
0
        private void OnCompilationStartAction(CompilationStartAnalysisContext context)
        {
            Compilation compilation = context.Compilation;
            var         xmlTypes    = new XxeSecurityTypes(compilation);

            if (!xmlTypes.IsAnyTypeReferenced())
            {
                return;
            }

            (bool dotnetCore, Version version) = compilation.GetDotNetFrameworkVersion();
            if (!dotnetCore && version == null)
            {
                return;
            }

            context.RegisterCodeBlockStartAction <CSharp.SyntaxKind>(
                c =>
            {
                var analyzer = new XxeAnalyzerCSharp(xmlTypes, dotnetCore || version >= new Version(4, 5, 2));
                analyzer.RegisterSyntaxNodeAction(c);
                c.RegisterCodeBlockEndAction(analyzer.AnalyzeCodeBlockEnd);
            });
        }