Esempio n. 1
0
        public void Execute(GeneratorExecutionContext context)
        {
            if (GeneratorContext.LaunchDebugger(context))
            {
                Debugger.Launch();
            }

            if (!"C#".Equals(context.ParseOptions.Language, StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            var outputContext = new GeneratorContext(context);

            var candidates = (context.SyntaxReceiver as SourceGeneratorSyntaxReceiver)?.Candidates;

            if (candidates == null || candidates.Count == 0)
            {
                outputContext.CleanUp();
                return;
            }

            using (new AssemblyResolver())
            {
                foreach (var entry in ExpandCandidates(context, candidates))
                {
                    context.CancellationToken.ThrowIfCancellationRequested();
                    var logger = new Logger(context, entry.Candidate, entry.Attribute);
                    InvokeGenerator(outputContext, entry.Factory, entry.Candidate, logger);
                }
            }

            outputContext.CleanUp();
        }