public void Execute(SourceGeneratorContext context) { try { var registrationSymbols = RegistrationSymbols.FromCompilation(context.Compilation); var containerClasses = context.LocateContainerSymbols(registrationSymbols.ContainerSymbol); var generator = new ContainerClassContentGenerator(context, registrationSymbols); foreach (var containerClass in containerClasses) { var hintName = $"Generated.{containerClass.FullyQualifiedName}"; var content = generator.GenerateClassString(containerClass); WriteOutDebugFile(hintName, content, context); context.AddSource(hintName, SourceText.From(content, Encoding.UTF8)); } } catch (DiagnosticException ex) { context.ReportDiagnostic(ex.Diagnostic); } catch (Exception ex) { var descriptor = new DiagnosticDescriptor(DiagnosticConstants.UnknownExceptionId, "Unexpected error", $"Unknown error during generation: {ex.GetType()} {ex.Message}", DiagnosticConstants.Category, DiagnosticSeverity.Error, true); context.ReportDiagnostic(Diagnostic.Create(descriptor, Location.None)); } }