private void InvokeGenerator(GeneratorContext context, ICodeGeneratorFactory factory, ClassDeclarationSyntax node) { var generatedCount = 0; CompilationUnit unit = default; foreach (var generator in factory.GetGenerators()) { context.CancellationToken.ThrowIfCancellationRequested(); if (_generatorCache.AddNew(node, generator.GetGeneratedMemberName())) { if (generatedCount == 0) { unit = new CompilationUnit(node); } else { unit.Output.AppendLine(); } generator.GenerateMemberDeclaration(unit.Output); generatedCount++; } } context.CancellationToken.ThrowIfCancellationRequested(); if (generatedCount > 0) { var source = unit.GetSourceText(); context.AddOutput(node, factory.GetHintName(), source); } }
private void InvokeGenerator( GeneratorContext context, ICodeGeneratorFactory factory, ClassDeclarationSyntax node, Logger logger) { if (!factory.Validate(logger)) { return; } var contract = new ContractDescription(factory.ServiceType); ShowWarnings(logger, contract, factory.ServiceType); var unit = new CompilationUnit(node); var generatedCount = 0; var imports = new HashSet <string>(StringComparer.Ordinal); foreach (var generator in factory.GetGenerators(contract, node).Concat(GetSharedGenerators(contract))) { context.CancellationToken.ThrowIfCancellationRequested(); if (_generatorCache.AddNew(node, generator.GetGeneratedMemberName())) { if (generatedCount > 0) { unit.Output.AppendLine(); } generator.GenerateMemberDeclaration(unit.Output); foreach (var i in generator.GetUsing()) { imports.Add(i); } generatedCount++; } } context.CancellationToken.ThrowIfCancellationRequested(); if (generatedCount > 0) { var source = unit.GetSourceText(GetSharedUsing().Concat(imports)); context.AddOutput(node, factory.GetHintName(contract), source); } }