public static void WriteTo(TextWriter writer, TemplateResult content) { if (content != null) { content.WriteTo(writer); } }
public TemplateResult RenderSection(string name, bool required) { EnsurePageCanBeRequestedDirectly("RenderSection"); if (PreviousSectionWriters.ContainsKey(name)) { var result = new TemplateResult(tw => { if (_renderedSections.Contains(name)) { throw new HttpException(String.Format("WebPageResources.WebPage_SectionAlreadyRendered {0}", name)); } var body = PreviousSectionWriters[name]; // Since the body can also call RenderSection, we need to temporarily remove // the current sections from the stack. var top = SectionWritersStack.Pop(); bool pushed = false; try { if (Output != tw) { OutputStack.Push(tw); pushed = true; } body(); } finally { if (pushed) { OutputStack.Pop(); } } SectionWritersStack.Push(top); _renderedSections.Add(name); }); return(result); } else if (required) { // If the section is not found, and it is not optional, throw an error. throw new HttpException(String.Format("WebPageResources.WebPage_SectionNotDefined {0}", name)); } else { // If the section is optional and not found, then don't do anything. return(null); } }
protected override void Write(TemplateResult result) { WriteTo(Output, result); }
public static void WriteTo(TextWriter writer, TemplateResult content) { if (content != null) content.WriteTo(writer); }
protected abstract void Write(TemplateResult result);