diff --git a/src/Microsoft.AspNetCore.Razor.Language/Extensions/SectionTargetExtension.cs b/src/Microsoft.AspNetCore.Razor.Language/Extensions/SectionTargetExtension.cs index 5e47ca17d7..e99c1598f3 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Extensions/SectionTargetExtension.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Extensions/SectionTargetExtension.cs @@ -7,6 +7,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions { public sealed class SectionTargetExtension : ISectionTargetExtension { + // Compatibility for 1.X projects + private const string DefaultWriterName = "__razor_section_writer"; + public static readonly string DefaultSectionMethodName = "DefineSection"; public string SectionMethodName { get; set; } = DefaultSectionMethodName; @@ -19,7 +22,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions .Write(node.SectionName) .Write("\", "); - using (context.CodeWriter.BuildAsyncLambda()) + using (context.CodeWriter.BuildAsyncLambda(DefaultWriterName)) { context.RenderChildren(node); } diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.codegen.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.codegen.cs index d0551e4366..fd3c971a71 100644 --- a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.codegen.cs +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.codegen.cs @@ -42,7 +42,7 @@ global::System.Object Section1 = null; #line default #line hidden - DefineSection("Section1", async() => { + DefineSection("Section1", async(__razor_section_writer) => { __InputTestTagHelper = CreateTagHelper(); #line 13 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml" __InputTestTagHelper.For = ModelExpressionProvider.CreateModelExpression(ViewData, __model => __model.Date); diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.mappings.txt b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.mappings.txt index c2b3302c4d..5e120c830d 100644 --- a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.mappings.txt +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.mappings.txt @@ -24,6 +24,6 @@ Generated Location: (1432:39,2 [46] ) Source Location: (222:12,21 [4] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml) |Date| -Generated Location: (1835:47,102 [4] ) +Generated Location: (1857:47,102 [4] ) |Date| diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_Runtime.codegen.cs b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_Runtime.codegen.cs index ba56f04308..95aa1a96a8 100644 --- a/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_Runtime.codegen.cs +++ b/test/Microsoft.AspNetCore.Mvc.Razor.Extensions.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_Runtime.codegen.cs @@ -51,7 +51,7 @@ namespace AspNetCore BeginContext(117, 26, true); WriteLiteral("\r\n
Some body
\r\n\r\n"); EndContext(); - DefineSection("Section1", async() => { + DefineSection("Section1", async(__razor_section_writer) => { BeginContext(162, 43, true); WriteLiteral("\r\n
This is in Section 1
\r\n "); EndContext(); diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/Extensions/SectionTargetExtensionTest.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/Extensions/SectionTargetExtensionTest.cs index c369432e3b..bfeb71ffb7 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/Extensions/SectionTargetExtensionTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/Extensions/SectionTargetExtensionTest.cs @@ -33,7 +33,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions extension.WriteSection(context, node); // Assert - var expected = @"CreateSection(""MySection"", async() => { + var expected = @"CreateSection(""MySection"", async(__razor_section_writer) => { Render Children } ); @@ -67,7 +67,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions extension.WriteSection(context, node); // Assert - var expected = @"CreateSection(""MySection"", async() => { + var expected = @"CreateSection(""MySection"", async(__razor_section_writer) => { Render Children } ); diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/DesignTime_DesignTime.codegen.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/DesignTime_DesignTime.codegen.cs index 0897ae157d..d30aea4b02 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/DesignTime_DesignTime.codegen.cs +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/DesignTime_DesignTime.codegen.cs @@ -53,7 +53,7 @@ __o = Foo(item => new Template(async(__razor_template_writer) => { #line default #line hidden - DefineSection("Footer", async() => { + DefineSection("Footer", async(__razor_section_writer) => { #line 14 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/DesignTime.cshtml" __o = bar; diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/DesignTime_DesignTime.mappings.txt b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/DesignTime_DesignTime.mappings.txt index a72db81cb6..87ab943dfc 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/DesignTime_DesignTime.mappings.txt +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/DesignTime_DesignTime.mappings.txt @@ -44,6 +44,6 @@ Generated Location: (1636:51,1 [1] ) Source Location: (204:13,5 [3] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/DesignTime.cshtml) |bar| -Generated Location: (1814:57,6 [3] ) +Generated Location: (1836:57,6 [3] ) |bar| diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.codegen.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.codegen.cs index b610f02553..556cf5e489 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.codegen.cs +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.codegen.cs @@ -33,7 +33,7 @@ global::System.Object NestedDelegates = null; #line default #line hidden - DefineSection("Section2", async() => { + DefineSection("Section2", async(__razor_section_writer) => { #line 8 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml" __o = thing; @@ -41,10 +41,10 @@ global::System.Object NestedDelegates = null; #line hidden } ); - DefineSection("Section1", async() => { + DefineSection("Section1", async(__razor_section_writer) => { } ); - DefineSection("NestedDelegates", async() => { + DefineSection("NestedDelegates", async(__razor_section_writer) => { #line 16 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml" Func f = diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.mappings.txt b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.mappings.txt index ff1262a84a..f6aedef836 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.mappings.txt +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_DesignTime.mappings.txt @@ -24,21 +24,21 @@ Generated Location: (1024:30,2 [44] ) Source Location: (123:7,22 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml) |thing| -Generated Location: (1257:37,22 [5] ) +Generated Location: (1279:37,22 [5] ) |thing| Source Location: (260:15,6 [27] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml) | Func f = | -Generated Location: (1560:48,6 [27] ) +Generated Location: (1626:48,6 [27] ) | Func f = | Source Location: (295:15,41 [4] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml) |item| -Generated Location: (1820:54,41 [4] ) +Generated Location: (1886:54,41 [4] ) |item| Source Location: (306:15,52 [2] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml) |; | -Generated Location: (2033:61,52 [2] ) +Generated Location: (2099:61,52 [2] ) |; | diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_Runtime.codegen.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_Runtime.codegen.cs index 128b60701f..179aa5c3d8 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_Runtime.codegen.cs +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections_Runtime.codegen.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests.TestFiles #line default #line hidden WriteLiteral("\r\n
This is in the Body>\r\n\r\n"); - DefineSection("Section2", async() => { + DefineSection("Section2", async(__razor_section_writer) => { WriteLiteral("\r\n { + DefineSection("Section1", async(__razor_section_writer) => { WriteLiteral("\r\n
This is in Section 1
\r\n"); } ); WriteLiteral("\r\n"); - DefineSection("NestedDelegates", async() => { + DefineSection("NestedDelegates", async(__razor_section_writer) => { WriteLiteral("\r\n"); #line 16 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml" Func f = diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/StringLiterals_DesignTime.codegen.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/StringLiterals_DesignTime.codegen.cs index 49a1737a04..e1a96c0d30 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/StringLiterals_DesignTime.codegen.cs +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/StringLiterals_DesignTime.codegen.cs @@ -23,10 +23,10 @@ global::System.Object WriteLiteralsToInHereAlso = null; #pragma warning disable 1998 public async System.Threading.Tasks.Task ExecuteAsync() { - DefineSection("WriteLiteralsToInHere", async() => { + DefineSection("WriteLiteralsToInHere", async(__razor_section_writer) => { } ); - DefineSection("WriteLiteralsToInHereAlso", async() => { + DefineSection("WriteLiteralsToInHereAlso", async(__razor_section_writer) => { } ); } diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/StringLiterals_Runtime.codegen.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/StringLiterals_Runtime.codegen.cs index ba174de703..e3770e0570 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/StringLiterals_Runtime.codegen.cs +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/StringLiterals_Runtime.codegen.cs @@ -96,7 +96,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests.TestFiles

This is line 84


"); - DefineSection("WriteLiteralsToInHere", async() => { + DefineSection("WriteLiteralsToInHere", async(__razor_section_writer) => { WriteLiteral(@"

This is line 1 nested

This is line 2 nested

@@ -222,7 +222,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests.TestFiles

This is line 42

This is line 43

hi!"); WriteLiteral("\r\n"); - DefineSection("WriteLiteralsToInHereAlso", async() => { + DefineSection("WriteLiteralsToInHereAlso", async(__razor_section_writer) => { WriteLiteral(@"

This is line 1 nested

This is line 2 nested

diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/TagHelpersInSection_Runtime.codegen.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/TagHelpersInSection_Runtime.codegen.cs index 1d3fbf2f83..d8924cbaab 100644 --- a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/TagHelpersInSection_Runtime.codegen.cs +++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/TagHelpersInSection_Runtime.codegen.cs @@ -37,7 +37,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests.TestFiles #line default #line hidden WriteLiteral("\r\n"); - DefineSection("MySection", async() => { + DefineSection("MySection", async(__razor_section_writer) => { WriteLiteral("\r\n
\r\n "); __tagHelperExecutionContext = __tagHelperScopeManager.Begin("mytaghelper", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, "test", async() => { WriteLiteral("\r\n In None ContentBehavior.\r\n "); diff --git a/test/Microsoft.AspNetCore.Razor.Test.MvcShim/Microsoft.AspNetCore.Mvc.Razor/RazorPageBase.cs b/test/Microsoft.AspNetCore.Razor.Test.MvcShim/Microsoft.AspNetCore.Mvc.Razor/RazorPageBase.cs index d1568a8075..a4916e5378 100644 --- a/test/Microsoft.AspNetCore.Razor.Test.MvcShim/Microsoft.AspNetCore.Mvc.Razor/RazorPageBase.cs +++ b/test/Microsoft.AspNetCore.Razor.Test.MvcShim/Microsoft.AspNetCore.Mvc.Razor/RazorPageBase.cs @@ -83,6 +83,11 @@ namespace Microsoft.AspNetCore.Mvc.Razor throw new NotImplementedException(); } + // Compatibility for 1.X projects + protected void DefineSection(string name, Func section) + { + } + public virtual void DefineSection(string name, RenderAsyncDelegate section) { }