public void Execute(RazorCodeDocument document)
        {
            var sourceTree = document.GetSourceTree();

            if (sourceTree == null)
            {
                throw new InvalidOperationException("Need to create the source tree");
            }

            var csharpDocument = document.GetGeneratedCSharpDocument();

            if (csharpDocument == null)
            {
                var csharpRenderers = Engine.Features.OfType <ICSharpRenderer>();
                if (!csharpRenderers.Any())
                {
                    throw new InvalidOperationException("Need to create the csharp document");
                }

                var directives           = document.GetCSharpRenderingDirectives() ?? Enumerable.Empty <IRazorDirective>();
                var rendererOrchestrator = new CSharpRendererOrchestrator(csharpRenderers, directives, _host, document.ErrorSink);
                csharpDocument = rendererOrchestrator.Render(sourceTree);

                document.SetGeneratedCSharpDocument(csharpDocument);
            }
        }
        public void Execute(RazorCodeDocument document)
        {
            var chunkTree = document.GetChunkTree();

            var classInfo = document.GetClassName();

            var chunkGeneratorContext = new ChunkGeneratorContext(_host, classInfo.Class, classInfo.Namespace, document.Source.Filename, shouldGenerateLinePragmas: true);

            chunkGeneratorContext.ChunkTreeBuilder = new AspNetCore.Razor.Chunks.ChunkTreeBuilder();
            chunkGeneratorContext.ChunkTreeBuilder.Root.Association = chunkTree.Root.Association;
            chunkGeneratorContext.ChunkTreeBuilder.Root.Start       = chunkTree.Root.Start;

            foreach (var chunk in chunkTree.Root.Children)
            {
                chunkGeneratorContext.ChunkTreeBuilder.Root.Children.Add(chunk);
            }

            var codeGeneratorContext = new CodeGeneratorContext(chunkGeneratorContext, document.ErrorSink);

            var codeGenerator       = new PageCodeGenerator(codeGeneratorContext);
            var codeGeneratorResult = codeGenerator.Generate();

            document.SetGeneratedCSharpDocument(new GeneratedCSharpDocument()
            {
                GeneratedCode = codeGeneratorResult.Code,
            });
        }