From 6cd13c441e020f116f29f8be5d0bb81b3dceaf20 Mon Sep 17 00:00:00 2001 From: Ajay Bhargav Baaskaran Date: Mon, 22 Feb 2016 11:52:27 -0800 Subject: [PATCH] [Fixes #691] Use WriteAttributeTo when TextWrites is not null --- .../Visitors/CSharpCodeVisitor.cs | 11 ++++++- .../CodeGenerator/Output/Sections.cs | 31 +++++++++++++------ .../CodeGenerator/Source/Sections.cshtml | 2 +- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/src/Microsoft.AspNetCore.Razor/CodeGenerators/Visitors/CSharpCodeVisitor.cs b/src/Microsoft.AspNetCore.Razor/CodeGenerators/Visitors/CSharpCodeVisitor.cs index 52d5fa6872..e6357d5769 100644 --- a/src/Microsoft.AspNetCore.Razor/CodeGenerators/Visitors/CSharpCodeVisitor.cs +++ b/src/Microsoft.AspNetCore.Razor/CodeGenerators/Visitors/CSharpCodeVisitor.cs @@ -368,7 +368,16 @@ namespace Microsoft.AspNetCore.Razor.CodeGenerators.Visitors Accept(chunk.Children); - Writer.WriteMethodInvocation(Context.Host.GeneratedClassContext.EndWriteAttributeMethodName); + if (!string.IsNullOrEmpty(Context.TargetWriterName)) + { + Writer.WriteStartMethodInvocation(Context.Host.GeneratedClassContext.EndWriteAttributeToMethodName) + .Write(Context.TargetWriterName) + .WriteEndMethodInvocation(); + } + else + { + Writer.WriteMethodInvocation(Context.Host.GeneratedClassContext.EndWriteAttributeMethodName); + } } protected override void Visit(SectionChunk chunk) diff --git a/test/Microsoft.AspNetCore.Razor.Test/TestFiles/CodeGenerator/Output/Sections.cs b/test/Microsoft.AspNetCore.Razor.Test/TestFiles/CodeGenerator/Output/Sections.cs index 2f4c60a1ca..f7e4419d3c 100644 --- a/test/Microsoft.AspNetCore.Razor.Test/TestFiles/CodeGenerator/Output/Sections.cs +++ b/test/Microsoft.AspNetCore.Razor.Test/TestFiles/CodeGenerator/Output/Sections.cs @@ -1,4 +1,4 @@ -#pragma checksum "Sections.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "bf45c2508895b4b9b3579bc193e7a0167ccdbdfb" +#pragma checksum "Sections.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "ec9a74381c339244a887565526c11056ece494a3" namespace TestOutput { using System; @@ -25,25 +25,36 @@ namespace TestOutput WriteLiteral("\r\n
This is in the Body>\r\n\r\n"); Instrumentation.EndContext(); DefineSection("Section2", async(__razor_section_writer) => { - Instrumentation.BeginContext(99, 39, true); - WriteLiteralTo(__razor_section_writer, "\r\n
This is in Section 2
\r\n"); + Instrumentation.BeginContext(99, 10, true); + WriteLiteralTo(__razor_section_writer, "\r\n
\r\n"); Instrumentation.EndContext(); } ); - Instrumentation.BeginContext(141, 2, true); + Instrumentation.BeginContext(161, 2, true); WriteLiteral("\r\n"); Instrumentation.EndContext(); DefineSection("Section1", async(__razor_section_writer) => { - Instrumentation.BeginContext(162, 39, true); + Instrumentation.BeginContext(182, 39, true); WriteLiteralTo(__razor_section_writer, "\r\n
This is in Section 1
\r\n"); Instrumentation.EndContext(); } ); - Instrumentation.BeginContext(204, 2, true); + Instrumentation.BeginContext(224, 2, true); WriteLiteral("\r\n"); Instrumentation.EndContext(); DefineSection("NestedDelegates", async(__razor_section_writer) => { - Instrumentation.BeginContext(232, 2, true); + Instrumentation.BeginContext(252, 2, true); WriteLiteralTo(__razor_section_writer, "\r\n"); Instrumentation.EndContext(); #line 16 "Sections.cshtml" @@ -59,17 +70,17 @@ namespace TestOutput #line hidden item => new Template(async(__razor_template_writer) => { - Instrumentation.BeginContext(268, 6, true); + Instrumentation.BeginContext(288, 6, true); WriteLiteralTo(__razor_template_writer, ""); Instrumentation.EndContext(); - Instrumentation.BeginContext(275, 4, false); + Instrumentation.BeginContext(295, 4, false); #line 16 "Sections.cshtml" WriteTo(__razor_template_writer, item); #line default #line hidden Instrumentation.EndContext(); - Instrumentation.BeginContext(279, 7, true); + Instrumentation.BeginContext(299, 7, true); WriteLiteralTo(__razor_template_writer, ""); Instrumentation.EndContext(); } diff --git a/test/Microsoft.AspNetCore.Razor.Test/TestFiles/CodeGenerator/Source/Sections.cshtml b/test/Microsoft.AspNetCore.Razor.Test/TestFiles/CodeGenerator/Source/Sections.cshtml index acebd4d0f5..952461002f 100644 --- a/test/Microsoft.AspNetCore.Razor.Test/TestFiles/CodeGenerator/Source/Sections.cshtml +++ b/test/Microsoft.AspNetCore.Razor.Test/TestFiles/CodeGenerator/Source/Sections.cshtml @@ -5,7 +5,7 @@
This is in the Body> @section Section2 { -
This is in Section 2
+
This is in Section 2
} @section Section1 {