Make 2.0 codegen compatible with 1.0 projects until multi-targeting is complete.
#1637
This commit is contained in:
parent
bf63704547
commit
5104e8c806
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ global::System.Object Section1 = null;
|
|||
|
||||
#line default
|
||||
#line hidden
|
||||
DefineSection("Section1", async() => {
|
||||
DefineSection("Section1", async(__razor_section_writer) => {
|
||||
__InputTestTagHelper = CreateTagHelper<global::InputTestTagHelper>();
|
||||
#line 13 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml"
|
||||
__InputTestTagHelper.For = ModelExpressionProvider.CreateModelExpression(ViewData, __model => __model.Date);
|
||||
|
|
|
|||
|
|
@ -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|
|
||||
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ namespace AspNetCore
|
|||
BeginContext(117, 26, true);
|
||||
WriteLiteral("\r\n<div>Some body</div>\r\n\r\n");
|
||||
EndContext();
|
||||
DefineSection("Section1", async() => {
|
||||
DefineSection("Section1", async(__razor_section_writer) => {
|
||||
BeginContext(162, 43, true);
|
||||
WriteLiteral("\r\n <div>This is in Section 1</div>\r\n ");
|
||||
EndContext();
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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|
|
||||
|
||||
|
|
|
|||
|
|
@ -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<dynamic, object> f =
|
||||
|
||||
|
|
|
|||
|
|
@ -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<dynamic, object> f = |
|
||||
Generated Location: (1560:48,6 [27] )
|
||||
Generated Location: (1626:48,6 [27] )
|
||||
| Func<dynamic, object> 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] )
|
||||
|; |
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests.TestFiles
|
|||
#line default
|
||||
#line hidden
|
||||
WriteLiteral("\r\n<div>This is in the Body>\r\n\r\n");
|
||||
DefineSection("Section2", async() => {
|
||||
DefineSection("Section2", async(__razor_section_writer) => {
|
||||
WriteLiteral("\r\n <div");
|
||||
BeginWriteAttribute("class", " class=\"", 109, "\"", 128, 2);
|
||||
WriteAttributeValue("", 117, "some", 117, 4, true);
|
||||
|
|
@ -30,12 +30,12 @@ WriteAttributeValue(" ", 121, thing, 122, 6, false);
|
|||
}
|
||||
);
|
||||
WriteLiteral("\r\n");
|
||||
DefineSection("Section1", async() => {
|
||||
DefineSection("Section1", async(__razor_section_writer) => {
|
||||
WriteLiteral("\r\n <div>This is in Section 1</div>\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<dynamic, object> f =
|
||||
|
|
|
|||
|
|
@ -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) => {
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests.TestFiles
|
|||
<p>This is line 84</p><br>
|
||||
|
||||
");
|
||||
DefineSection("WriteLiteralsToInHere", async() => {
|
||||
DefineSection("WriteLiteralsToInHere", async(__razor_section_writer) => {
|
||||
WriteLiteral(@"
|
||||
<p>This is line 1 nested</p>
|
||||
<p>This is line 2 nested</p>
|
||||
|
|
@ -222,7 +222,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests.TestFiles
|
|||
<p>This is line 42</p>
|
||||
<p>This is line 43</p>hi!");
|
||||
WriteLiteral("\r\n");
|
||||
DefineSection("WriteLiteralsToInHereAlso", async() => {
|
||||
DefineSection("WriteLiteralsToInHereAlso", async(__razor_section_writer) => {
|
||||
WriteLiteral(@"
|
||||
<p>This is line 1 nested</p>
|
||||
<p>This is line 2 nested</p>
|
||||
|
|
|
|||
|
|
@ -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 <div>\r\n ");
|
||||
__tagHelperExecutionContext = __tagHelperScopeManager.Begin("mytaghelper", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, "test", async() => {
|
||||
WriteLiteral("\r\n In None ContentBehavior.\r\n ");
|
||||
|
|
|
|||
|
|
@ -83,6 +83,11 @@ namespace Microsoft.AspNetCore.Mvc.Razor
|
|||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
// Compatibility for 1.X projects
|
||||
protected void DefineSection(string name, Func<object, Task> section)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void DefineSection(string name, RenderAsyncDelegate section)
|
||||
{
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue