/// <summary> /// Renders the content of a block helper. /// </summary> /// <param name="children">The children of the helper block.</param> /// <param name="context">The render context.</param> /// <param name="data">The new data model.</param> /// <returns>The string content of the result.</returns> private string RenderHelperChildren(IEnumerable <SyntaxTreeNode> children, RenderContext context, object data) { RenderContext targetContext = context; RenderContextScope scope = null; if (data != null) { scope = context.BeginScope(data); targetContext = scope.ScopeContext; } using (var writer = new StringWriter()) { var renderer = new RenderingParserVisitor(writer, targetContext, context.ModelMetadataProvider); foreach (var node in children) { node.Accept(renderer); } if (scope != null) { scope.Dispose(); } return(writer.GetStringBuilder().ToString()); } }
/// <summary> /// Creates a <see cref="RenderContext"/> using the renderer provided. /// </summary> /// <param name="renderer">The renderering parser visitor.</param> /// <param name="model">The model.</param> /// <returns>The render context.</returns> public static RenderContext CreateRenderContext(RenderingParserVisitor renderer, object model = null) { if (renderer == null) { throw new ArgumentNullException("renderer"); } var context = new RenderContext(renderer) { TemplateData = new TemplateData() { Model = model, ModelMetadata = (model == null) ? null : renderer.ModelMetadataProvider.GetMetadataForType(() => model, model.GetType()) }, ModelMetadataProvider = renderer.ModelMetadataProvider, Service = renderer.Service }; return(context); }