diff --git a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/CSharpCodeWriter.cs b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/CSharpCodeWriter.cs index 41435495d1..c6ed4110eb 100644 --- a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/CSharpCodeWriter.cs +++ b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/CSharpCodeWriter.cs @@ -284,13 +284,23 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp return new CSharpCodeWritingScope(this); } - public CSharpCodeWritingScope BuildLambda(params string[] parameterNames) - { - return BuildLambda(true, parameterNames); - } - public CSharpCodeWritingScope BuildLambda(bool endLine, params string[] parameterNames) { + return BuildLambda(endLine, async: false, parameterNames: parameterNames); + } + + public CSharpCodeWritingScope BuildAsyncLambda(bool endLine, params string[] parameterNames) + { + return BuildLambda(endLine, async: true, parameterNames: parameterNames); + } + + private CSharpCodeWritingScope BuildLambda(bool endLine, bool async, string[] parameterNames) + { + if (async) + { + Write("async"); + } + Write("(").Write(string.Join(", ", parameterNames)).Write(") => "); var scope = new CSharpCodeWritingScope(this); diff --git a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpCodeVisitor.cs b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpCodeVisitor.cs index eff6beed4b..14d4d0c682 100644 --- a/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpCodeVisitor.cs +++ b/src/Microsoft.AspNet.Razor/Generator/Compiler/CodeBuilder/CSharp/Visitors/CSharpCodeVisitor.cs @@ -320,19 +320,16 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp { Writer.WriteStartMethodInvocation(Context.Host.GeneratedClassContext.DefineSectionMethodName) .WriteStringLiteral(chunk.Name) - .WriteParameterSeparator() - .WriteStartNewObject(Context.Host.GeneratedClassContext.TemplateTypeName); + .WriteParameterSeparator(); var currentTargetWriterName = Context.TargetWriterName; Context.TargetWriterName = TemplateWriterName; - using (Writer.BuildLambda(endLine: false, parameterNames: TemplateWriterName)) + using (Writer.BuildAsyncLambda(endLine: false, parameterNames: TemplateWriterName)) { Accept(chunk.Children); } Context.TargetWriterName = currentTargetWriterName; - - Writer.WriteEndMethodInvocation(endLine: false); Writer.WriteEndMethodInvocation(); } diff --git a/test/Microsoft.AspNet.Razor.Test/Generator/CSharpRazorCodeGeneratorTest.cs b/test/Microsoft.AspNet.Razor.Test/Generator/CSharpRazorCodeGeneratorTest.cs index 501e9e9c98..83e91c07f7 100644 --- a/test/Microsoft.AspNet.Razor.Test/Generator/CSharpRazorCodeGeneratorTest.cs +++ b/test/Microsoft.AspNet.Razor.Test/Generator/CSharpRazorCodeGeneratorTest.cs @@ -294,7 +294,7 @@ namespace Microsoft.AspNet.Razor.Test.Generator BuildLineMapping(113, 7, 2, 1262, 71, 6, 12), BuildLineMapping(129, 8, 1, 1343, 76, 6, 4), BuildLineMapping(142, 8, 1443, 78, 14, 3), - BuildLineMapping(204, 13, 5, 1638, 90, 6, 3) + BuildLineMapping(204, 13, 5, 1630, 90, 6, 3) }); } diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/DesignTime.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/DesignTime.cs index 16851acdee..b99092ae53 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/DesignTime.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/DesignTime.cs @@ -86,14 +86,14 @@ __o = Foo(item => new Template((__razor_template_writer) => { #line default #line hidden - DefineSection("Footer", new Template((__razor_template_writer) => { + DefineSection("Footer", async(__razor_template_writer) => { #line 14 "DesignTime.cshtml" __o = bar; #line default #line hidden } - )); + ); } #pragma warning restore 1998 } diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/ResolveUrl.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/ResolveUrl.cs index b117562219..e380b895a2 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/ResolveUrl.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/ResolveUrl.cs @@ -92,7 +92,7 @@ namespace TestOutput Instrumentation.BeginContext(474, 4, true); WriteLiteral("\r\n\r\n"); Instrumentation.EndContext(); - DefineSection("Foo", new Template((__razor_template_writer) => { + DefineSection("Foo", async(__razor_template_writer) => { Instrumentation.BeginContext(492, 8, true); WriteLiteralTo(__razor_template_writer, "\r\n Crazy Url!\r\n"); Instrumentation.EndContext(); } - )); + ); } #pragma warning restore 1998 } diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/Sections.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/Sections.cs index 529a0236a7..d5e57d2460 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/Sections.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/Sections.cs @@ -24,21 +24,21 @@ namespace TestOutput Instrumentation.BeginContext(47, 33, true); WriteLiteral("\r\n\r\n