Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

Commit 108b2fa

Browse files
author
NTaylorMullen
committed
Added support for @Helper and @section.
1 parent 2b5f2ee commit 108b2fa

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/CSharpTagHelperCodeRenderer.cs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -310,11 +310,8 @@ private void RenderTagHelperBody(IList<Chunk> children, ContentBehavior contentB
310310
// If content behavior is modify we need to use a different writer to buffer the body.
311311
if (contentBehavior == ContentBehavior.Modify)
312312
{
313-
BuildBufferedWritingScope(() =>
314-
{
315-
// Render all of the tag helper children
316-
_bodyVisitor.Accept(children);
317-
});
313+
// Render all of the tag helper children in a buffered writing scope
314+
BuildBufferedWritingScope(children);
318315
}
319316
else
320317
{
@@ -401,21 +398,27 @@ private void RenderQuotedAttributeValue(string value, TagHelperAttributeDescript
401398

402399
private void BuildBufferedAttributeValue(Chunk htmlAttributeChunk)
403400
{
404-
BuildBufferedWritingScope(renderCode: () =>
405-
{
406-
// Render the HTML's attribute chunk(s).
407-
_bodyVisitor.Accept(htmlAttributeChunk);
408-
});
401+
// Render a buffered writing scope for the html attribute value.
402+
BuildBufferedWritingScope(new[] { htmlAttributeChunk });
409403
}
410404

411-
private void BuildBufferedWritingScope(Action renderCode)
405+
private void BuildBufferedWritingScope(IList<Chunk> chunks)
412406
{
407+
// We're building a writing scope around the provided chunks which captures everything written from the
408+
// page. Therefore, we do not want to write to any other buffer since we're using the pages buffer to
409+
// ensure we capture all content that's written, directly or indirectly.
410+
var oldWriter = _context.TargetWriterName;
411+
_context.TargetWriterName = null;
412+
413413
_writer.WriteMethodInvocation(_tagHelperContext.StartWritingScopeMethodName);
414414

415-
renderCode();
415+
_bodyVisitor.Accept(chunks);
416416

417417
_writer.WriteStartAssignment(StringValueBufferVariableName)
418418
.WriteMethodInvocation(_tagHelperContext.EndWritingScopeMethodName);
419+
420+
// Reset the writer/buffer back to what it was, no longer in a writing scope.
421+
_context.TargetWriterName = oldWriter;
419422
}
420423

421424
private void RenderAttributeValue(TagHelperAttributeDescriptor attributeDescriptor,

0 commit comments

Comments
 (0)