Make 2.0 codegen compatible with 1.0 projects until multi-targeting is complete.

#1637
This commit is contained in:
N. Taylor Mullen 2017-08-22 15:00:26 -07:00
parent bf63704547
commit 5104e8c806
14 changed files with 31 additions and 23 deletions

View File

@ -7,6 +7,9 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions
{ {
public sealed class SectionTargetExtension : ISectionTargetExtension public sealed class SectionTargetExtension : ISectionTargetExtension
{ {
// Compatibility for 1.X projects
private const string DefaultWriterName = "__razor_section_writer";
public static readonly string DefaultSectionMethodName = "DefineSection"; public static readonly string DefaultSectionMethodName = "DefineSection";
public string SectionMethodName { get; set; } = DefaultSectionMethodName; public string SectionMethodName { get; set; } = DefaultSectionMethodName;
@ -19,7 +22,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions
.Write(node.SectionName) .Write(node.SectionName)
.Write("\", "); .Write("\", ");
using (context.CodeWriter.BuildAsyncLambda()) using (context.CodeWriter.BuildAsyncLambda(DefaultWriterName))
{ {
context.RenderChildren(node); context.RenderChildren(node);
} }

View File

@ -42,7 +42,7 @@ global::System.Object Section1 = null;
#line default #line default
#line hidden #line hidden
DefineSection("Section1", async() => { DefineSection("Section1", async(__razor_section_writer) => {
__InputTestTagHelper = CreateTagHelper<global::InputTestTagHelper>(); __InputTestTagHelper = CreateTagHelper<global::InputTestTagHelper>();
#line 13 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml" #line 13 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml"
__InputTestTagHelper.For = ModelExpressionProvider.CreateModelExpression(ViewData, __model => __model.Date); __InputTestTagHelper.For = ModelExpressionProvider.CreateModelExpression(ViewData, __model => __model.Date);

View File

@ -24,6 +24,6 @@ Generated Location: (1432:39,2 [46] )
Source Location: (222:12,21 [4] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml) Source Location: (222:12,21 [4] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml)
|Date| |Date|
Generated Location: (1835:47,102 [4] ) Generated Location: (1857:47,102 [4] )
|Date| |Date|

View File

@ -51,7 +51,7 @@ namespace AspNetCore
BeginContext(117, 26, true); BeginContext(117, 26, true);
WriteLiteral("\r\n<div>Some body</div>\r\n\r\n"); WriteLiteral("\r\n<div>Some body</div>\r\n\r\n");
EndContext(); EndContext();
DefineSection("Section1", async() => { DefineSection("Section1", async(__razor_section_writer) => {
BeginContext(162, 43, true); BeginContext(162, 43, true);
WriteLiteral("\r\n <div>This is in Section 1</div>\r\n "); WriteLiteral("\r\n <div>This is in Section 1</div>\r\n ");
EndContext(); EndContext();

View File

@ -33,7 +33,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions
extension.WriteSection(context, node); extension.WriteSection(context, node);
// Assert // Assert
var expected = @"CreateSection(""MySection"", async() => { var expected = @"CreateSection(""MySection"", async(__razor_section_writer) => {
Render Children Render Children
} }
); );
@ -67,7 +67,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Extensions
extension.WriteSection(context, node); extension.WriteSection(context, node);
// Assert // Assert
var expected = @"CreateSection(""MySection"", async() => { var expected = @"CreateSection(""MySection"", async(__razor_section_writer) => {
Render Children Render Children
} }
); );

View File

@ -53,7 +53,7 @@ __o = Foo(item => new Template(async(__razor_template_writer) => {
#line default #line default
#line hidden #line hidden
DefineSection("Footer", async() => { DefineSection("Footer", async(__razor_section_writer) => {
#line 14 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/DesignTime.cshtml" #line 14 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/DesignTime.cshtml"
__o = bar; __o = bar;

View File

@ -44,6 +44,6 @@ Generated Location: (1636:51,1 [1] )
Source Location: (204:13,5 [3] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/DesignTime.cshtml) Source Location: (204:13,5 [3] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/DesignTime.cshtml)
|bar| |bar|
Generated Location: (1814:57,6 [3] ) Generated Location: (1836:57,6 [3] )
|bar| |bar|

View File

@ -33,7 +33,7 @@ global::System.Object NestedDelegates = null;
#line default #line default
#line hidden #line hidden
DefineSection("Section2", async() => { DefineSection("Section2", async(__razor_section_writer) => {
#line 8 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml" #line 8 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml"
__o = thing; __o = thing;
@ -41,10 +41,10 @@ global::System.Object NestedDelegates = null;
#line hidden #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" #line 16 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml"
Func<dynamic, object> f = Func<dynamic, object> f =

View File

@ -24,21 +24,21 @@ Generated Location: (1024:30,2 [44] )
Source Location: (123:7,22 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml) Source Location: (123:7,22 [5] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml)
|thing| |thing|
Generated Location: (1257:37,22 [5] ) Generated Location: (1279:37,22 [5] )
|thing| |thing|
Source Location: (260:15,6 [27] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml) Source Location: (260:15,6 [27] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml)
| Func<dynamic, object> f = | | Func<dynamic, object> f = |
Generated Location: (1560:48,6 [27] ) Generated Location: (1626:48,6 [27] )
| Func<dynamic, object> f = | | Func<dynamic, object> f = |
Source Location: (295:15,41 [4] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml) Source Location: (295:15,41 [4] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml)
|item| |item|
Generated Location: (1820:54,41 [4] ) Generated Location: (1886:54,41 [4] )
|item| |item|
Source Location: (306:15,52 [2] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml) Source Location: (306:15,52 [2] TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml)
|; | |; |
Generated Location: (2033:61,52 [2] ) Generated Location: (2099:61,52 [2] )
|; | |; |

View File

@ -16,7 +16,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests.TestFiles
#line default #line default
#line hidden #line hidden
WriteLiteral("\r\n<div>This is in the Body>\r\n\r\n"); 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"); WriteLiteral("\r\n <div");
BeginWriteAttribute("class", " class=\"", 109, "\"", 128, 2); BeginWriteAttribute("class", " class=\"", 109, "\"", 128, 2);
WriteAttributeValue("", 117, "some", 117, 4, true); WriteAttributeValue("", 117, "some", 117, 4, true);
@ -30,12 +30,12 @@ WriteAttributeValue(" ", 121, thing, 122, 6, false);
} }
); );
WriteLiteral("\r\n"); 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 <div>This is in Section 1</div>\r\n");
} }
); );
WriteLiteral("\r\n"); WriteLiteral("\r\n");
DefineSection("NestedDelegates", async() => { DefineSection("NestedDelegates", async(__razor_section_writer) => {
WriteLiteral("\r\n"); WriteLiteral("\r\n");
#line 16 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml" #line 16 "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/Sections.cshtml"
Func<dynamic, object> f = Func<dynamic, object> f =

View File

@ -23,10 +23,10 @@ global::System.Object WriteLiteralsToInHereAlso = null;
#pragma warning disable 1998 #pragma warning disable 1998
public async System.Threading.Tasks.Task ExecuteAsync() 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) => {
} }
); );
} }

View File

@ -96,7 +96,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests.TestFiles
<p>This is line 84</p><br> <p>This is line 84</p><br>
"); ");
DefineSection("WriteLiteralsToInHere", async() => { DefineSection("WriteLiteralsToInHere", async(__razor_section_writer) => {
WriteLiteral(@" WriteLiteral(@"
<p>This is line 1 nested</p> <p>This is line 1 nested</p>
<p>This is line 2 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 42</p>
<p>This is line 43</p>hi!"); <p>This is line 43</p>hi!");
WriteLiteral("\r\n"); WriteLiteral("\r\n");
DefineSection("WriteLiteralsToInHereAlso", async() => { DefineSection("WriteLiteralsToInHereAlso", async(__razor_section_writer) => {
WriteLiteral(@" WriteLiteral(@"
<p>This is line 1 nested</p> <p>This is line 1 nested</p>
<p>This is line 2 nested</p> <p>This is line 2 nested</p>

View File

@ -37,7 +37,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests.TestFiles
#line default #line default
#line hidden #line hidden
WriteLiteral("\r\n"); WriteLiteral("\r\n");
DefineSection("MySection", async() => { DefineSection("MySection", async(__razor_section_writer) => {
WriteLiteral("\r\n <div>\r\n "); WriteLiteral("\r\n <div>\r\n ");
__tagHelperExecutionContext = __tagHelperScopeManager.Begin("mytaghelper", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, "test", async() => { __tagHelperExecutionContext = __tagHelperScopeManager.Begin("mytaghelper", global::Microsoft.AspNetCore.Razor.TagHelpers.TagMode.StartTagAndEndTag, "test", async() => {
WriteLiteral("\r\n In None ContentBehavior.\r\n "); WriteLiteral("\r\n In None ContentBehavior.\r\n ");

View File

@ -83,6 +83,11 @@ namespace Microsoft.AspNetCore.Mvc.Razor
throw new NotImplementedException(); 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) public virtual void DefineSection(string name, RenderAsyncDelegate section)
{ {
} }