コード例 #1
0
        public override void Initialize(AnalysisContext context)
        {
            context.EnableConcurrentExecution();
            context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);
            context.RegisterCompilationStartAction(compilationStartAnalysisContext =>
            {
                var syntaxCollector = new SyntaxCollector();
                compilationStartAnalysisContext.RegisterSyntaxNodeAction(analysisContext =>
                {
                    syntaxCollector.OnVisitSyntaxNode(analysisContext.Node);
                }, SyntaxKind.Attribute, SyntaxKind.InvocationExpression);

                compilationStartAnalysisContext.RegisterCompilationEndAction(compilationContext =>
                {
                    Execute(new GeneratorContext(compilationContext, syntaxCollector));
                });
            });
        }
コード例 #2
0
 public GeneratorContext(GeneratorExecutionContext generatorExecutionContext)
 {
     _syntaxCollector            = (SyntaxCollector)generatorExecutionContext.SyntaxReceiver !;
     _compilationAnalysisContext = null;
     _generatorExecutionContext  = generatorExecutionContext;
 }
コード例 #3
0
 public GeneratorContext(CompilationAnalysisContext compilationAnalysisContext, SyntaxCollector syntaxCollector)
 {
     _compilationAnalysisContext = compilationAnalysisContext;
     _syntaxCollector            = syntaxCollector;
     _generatorExecutionContext  = null;
 }