Change Execute rendering to be async.

Added the using statement required for async rendering.
This commit is contained in:
N. Taylor Mullen 2014-03-13 16:18:44 -07:00
parent b1c49a2535
commit 5912475a24
3 changed files with 14 additions and 5 deletions

View File

@ -41,9 +41,9 @@ namespace Microsoft.AspNet.Razor
return new CSharpRazorCodeGenerator(className, rootNamespaceName, sourceFileName, host);
}
public override CodeBuilder CreateCodeBuilder(CodeGeneratorContext codeGeneratorContext)
public override CodeBuilder CreateCodeBuilder(CodeGeneratorContext context)
{
return new CSharpCodeBuilder(codeGeneratorContext);
return new CSharpCodeBuilder(context);
}
}
}

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
{
@ -43,7 +44,7 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
new CSharpHelperVisitor(writer, Context).Accept(Tree.Chunks);
new CSharpTypeMemberVisitor(writer, Context).Accept(Tree.Chunks);
new CSharpDesignTimeHelpersVisitor(writer, Context).AcceptTree(Tree);
writer.WriteLineHiddenDirective();
using (writer.BuildConstructor(Context.ClassName))
{
@ -53,7 +54,7 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
// Add space inbetween constructor and method body
writer.WriteLine();
using (writer.BuildMethodDeclaration("public override", "void", Host.GeneratedClassContext.ExecuteMethodName))
using (writer.BuildMethodDeclaration("public override async", "Task", Host.GeneratedClassContext.ExecuteMethodName))
{
new CSharpCodeVisitor(writer, Context).Accept(Tree.Chunks);
}
@ -78,6 +79,14 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
{
writer.WriteUsing(import);
}
string taskNamespace = typeof(Task).Namespace;
// We need to add the task namespace but ONLY if it hasn't been added by the default imports or using imports yet.
if(!defaultImports.Contains(taskNamespace) && !usingVisitor.ImportedUsings.Contains(taskNamespace))
{
writer.WriteUsing(taskNamespace);
}
}
}
}

View File

@ -11,7 +11,7 @@ namespace Microsoft.AspNet.Razor.Generator
{
public static readonly string DefaultWriteMethodName = "Write";
public static readonly string DefaultWriteLiteralMethodName = "WriteLiteral";
public static readonly string DefaultExecuteMethodName = "Execute";
public static readonly string DefaultExecuteMethodName = "ExecuteAsync";
public static readonly string DefaultLayoutPropertyName = "Layout";
public static readonly string DefaultWriteAttributeMethodName = "WriteAttribute";
public static readonly string DefaultWriteAttributeToMethodName = "WriteAttributeTo";