From 02d6b00d8f5d7fbc452c1c69a3330dddba9f3c91 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Wed, 4 Nov 2015 16:04:29 -0800 Subject: [PATCH] Generate `async` lambda for template attributes. - Template attributes should be of type `Func`. We weren't generating an `async` lambda for attributes prior to this change resulting in a compilation failure when used at runtime and the inability to `@await` code (unless a user returns some sort of `Task`). - Updated code generation files to reflect the new code generation behavior. #594 --- .../CodeGenerators/Visitors/CSharpCodeVisitor.cs | 2 +- .../TestFiles/CodeGenerator/Output/ConditionalAttributes.cs | 2 +- .../CodeGenerator/Output/DynamicAttributeTagHelpers.cs | 6 +++--- .../TestFiles/CodeGenerator/Output/InlineBlocks.cs | 2 +- .../Output/TransitionsInTagHelperAttributes.cs | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.AspNet.Razor/CodeGenerators/Visitors/CSharpCodeVisitor.cs b/src/Microsoft.AspNet.Razor/CodeGenerators/Visitors/CSharpCodeVisitor.cs index a6d6b27943..9e6157175b 100644 --- a/src/Microsoft.AspNet.Razor/CodeGenerators/Visitors/CSharpCodeVisitor.cs +++ b/src/Microsoft.AspNet.Razor/CodeGenerators/Visitors/CSharpCodeVisitor.cs @@ -236,7 +236,7 @@ namespace Microsoft.AspNet.Razor.CodeGenerators.Visitors .WriteParameterSeparator() .WriteStartNewObject(Context.Host.GeneratedClassContext.TemplateTypeName); - using (Writer.BuildLambda(endLine: false, parameterNames: ValueWriterName)) + using (Writer.BuildAsyncLambda(endLine: false, parameterNames: ValueWriterName)) { Accept(chunk.Children); } diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/Output/ConditionalAttributes.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/Output/ConditionalAttributes.cs index c48e2cb35c..f1ab19a994 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/Output/ConditionalAttributes.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/Output/ConditionalAttributes.cs @@ -79,7 +79,7 @@ WriteAttributeValue(" ", 232, ch, 233, 4, false); WriteLiteral(" />\r\n { + WriteAttributeValue("", 256, new Template(async(__razor_attribute_value_writer) => { #line 10 "ConditionalAttributes.cshtml" if(cls != null) { diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/Output/DynamicAttributeTagHelpers.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/Output/DynamicAttributeTagHelpers.cs index 0f613b3c10..d2e4df0801 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/Output/DynamicAttributeTagHelpers.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/Output/DynamicAttributeTagHelpers.cs @@ -53,7 +53,7 @@ AddHtmlAttributeValue(" ", 57, DateTime.Now, 58, 14, false); __TestNamespace_InputTagHelper = CreateTagHelper(); __tagHelperExecutionContext.Add(__TestNamespace_InputTagHelper); BeginAddHtmlAttributeValues(__tagHelperExecutionContext, "unbound", 2); - AddHtmlAttributeValue("", 95, new Template((__razor_attribute_value_writer) => { + AddHtmlAttributeValue("", 95, new Template(async(__razor_attribute_value_writer) => { #line 5 "DynamicAttributeTagHelpers.cshtml" if (true) { @@ -186,7 +186,7 @@ AddHtmlAttributeValue("", 347, long.MinValue, 347, 14, false); #line default #line hidden - AddHtmlAttributeValue(" ", 361, new Template((__razor_attribute_value_writer) => { + AddHtmlAttributeValue(" ", 361, new Template(async(__razor_attribute_value_writer) => { #line 10 "DynamicAttributeTagHelpers.cshtml" if (true) { @@ -273,7 +273,7 @@ AddHtmlAttributeValue(" ", 490, int.MaxValue, 491, 14, false); __TestNamespace_InputTagHelper = CreateTagHelper(); __tagHelperExecutionContext.Add(__TestNamespace_InputTagHelper); BeginAddHtmlAttributeValues(__tagHelperExecutionContext, "unbound", 1); - AddHtmlAttributeValue("", 528, new Template((__razor_attribute_value_writer) => { + AddHtmlAttributeValue("", 528, new Template(async(__razor_attribute_value_writer) => { #line 14 "DynamicAttributeTagHelpers.cshtml" if (true) { diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/Output/InlineBlocks.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/Output/InlineBlocks.cs index 3cdef84f8f..919ab4b1b9 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/Output/InlineBlocks.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/Output/InlineBlocks.cs @@ -21,7 +21,7 @@ namespace TestOutput WriteLiteral("(string link) {\r\n { + WriteAttributeValue("", 43, new Template(async(__razor_attribute_value_writer) => { #line 2 "InlineBlocks.cshtml" if(link != null) { diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/Output/TransitionsInTagHelperAttributes.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/Output/TransitionsInTagHelperAttributes.cs index b0a398d66e..72637c2668 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/Output/TransitionsInTagHelperAttributes.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/Output/TransitionsInTagHelperAttributes.cs @@ -43,7 +43,7 @@ namespace TestOutput __TestNamespace_PTagHelper = CreateTagHelper(); __tagHelperExecutionContext.Add(__TestNamespace_PTagHelper); BeginAddHtmlAttributeValues(__tagHelperExecutionContext, "class", 1); - AddHtmlAttributeValue("", 109, new Template((__razor_attribute_value_writer) => { + AddHtmlAttributeValue("", 109, new Template(async(__razor_attribute_value_writer) => { } ), 109, 6, false); EndAddHtmlAttributeValues(__tagHelperExecutionContext);