public void Execute(RazorCodeDocument document) { var chunkTree = document.GetChunkTree(); if (chunkTree == null) { var loweringFeature = Engine.Features.OfType <IChunkTreeLoweringFeature>().FirstOrDefault(); if (loweringFeature == null) { throw new InvalidOperationException("Need to create the chunk tree"); } var syntaxTree = document.GetSyntaxTree(); if (syntaxTree == null) { throw new InvalidOperationException("Need to create the syntax tree"); } chunkTree = loweringFeature.Execute(document, syntaxTree); } var passes = Engine.Features.OfType <IChunkTreePass>().OrderBy(p => p.Order).ToArray(); foreach (var pass in passes) { chunkTree = pass.Execute(document, chunkTree); } document.SetChunkTree(chunkTree); }
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, }); }