private bool IsCompletelyInlined(DomContainer document, IProfilerScope scope) { if (document.ChildNodes.Count != 1) { return(false); } var hxlRenderElement = document.ChildNodes[0] as HxlRenderWorkElement; if (hxlRenderElement == null || hxlRenderElement.ChildNodes.Count > 0) { return(false); } scope.AddMetric("completelyInlined", true); CSTemplateGenerator g = new CSTemplateGenerator(); ApplySettings(template, g); g.TransformTextCore = string.Join(Environment.NewLine, hxlRenderElement.PreLines) + string.Join(Environment.NewLine, hxlRenderElement.PostLines); g.HasDocument = false; string code = g.TransformText(); output.WriteLine(code); if (Metrics.EnableAdvancedParserMetrics) { scope.SourceCodeMetrics(true, 1, code.Length, 0, 0); } return(true); }
public void WriteCode(IProfilerScope scope) { var result = this.template.PreparedDocument; if (IsCompletelyInlined(result, scope)) { return; } // We buffer this output so that we can present variables upfront for readability var buffer = new StringWriter(); var visitor = new GenerateInitTextVisitor(buffer, this.template); visitor.Visit(result); CSTemplateGenerator g = new CSTemplateGenerator(); ApplySettings(template, g); g.DomNodeVariables = visitor.AllDomNodeVariables; g.DomObjectVariables = visitor.AllDomObjectVariables; g.InitializeComponent = buffer.ToString(); g.RenderIslands = visitor.RenderIslands; g.HasDocument = true; g.Accessibility = "public"; string code = g.TransformText(); output.WriteLine(code); if (Metrics.EnableAdvancedParserMetrics) { scope.SourceCodeMetrics(false, this.template.PreparedDocument.DescendantNodes.Count(), code.Length, visitor.RenderIslandCount, g.DomNodeVariables.Count + g.DomNodeVariables.Count); } }