Пример #1
0
        public void Execute(GeneratorExecutionContext context)
        {
            if (context.SyntaxReceiver is SyntaxReceiver receiver)
            {
                var generator = new SourceTextGenerator(context.Compilation);
                foreach (var target in receiver.Targets.Values)
                {
                    var sourceText = GenerateSourceText(generator, target);
                    context.AddSource($"{target.Class.Identifier}.Generated.cs", sourceText);

                    ReportGeneratorDiagnostics(context, generator);
                }

                ReportProgress(context, receiver.Targets.Values.Count);
            }
        }
Пример #2
0
 private static void ReportGeneratorDiagnostics(GeneratorExecutionContext context, SourceTextGenerator generator)
 => generator.Diagnostics.ToList().ForEach(diagnostic => context.ReportDiagnostic(diagnostic));
Пример #3
0
 private static SourceText GenerateSourceText(SourceTextGenerator generator, SystemClass target)
 => generator.Generate(target);