Add a virtual BuildClassDeclaration method to CSharpCodeBuilder.

This extensibility point needs to be an override and not a pure visitor due to how the class declaration is created (only 1 right way to write the class).

#76
This commit is contained in:
N. Taylor Mullen 2014-06-23 17:30:43 -07:00 committed by NTaylorMullen
parent e4911323a6
commit c7545a0354
1 changed files with 13 additions and 7 deletions

View File

@ -31,15 +31,9 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
// Separate the usings and the class // Separate the usings and the class
writer.WriteLine(); writer.WriteLine();
var baseTypeVisitor = new CSharpBaseTypeVisitor(writer, Context);
baseTypeVisitor.Accept(Tree.Chunks);
string baseType = baseTypeVisitor.CurrentBaseType ?? Host.DefaultBaseClass;
new CSharpClassAttributeVisitor(writer, Context).Accept(Tree.Chunks); new CSharpClassAttributeVisitor(writer, Context).Accept(Tree.Chunks);
IEnumerable<string> baseTypes = String.IsNullOrEmpty(baseType) ? Enumerable.Empty<string>() : using (BuildClassDeclaration(writer))
new string[] { baseType };
using (writer.BuildClassDeclaration("public", Context.ClassName, baseTypes))
{ {
if (Host.DesignTimeMode) if (Host.DesignTimeMode)
{ {
@ -68,6 +62,18 @@ namespace Microsoft.AspNet.Razor.Generator.Compiler.CSharp
return new CodeBuilderResult(writer.GenerateCode(), writer.LineMappingManager.Mappings); return new CodeBuilderResult(writer.GenerateCode(), writer.LineMappingManager.Mappings);
} }
protected virtual CSharpCodeWritingScope BuildClassDeclaration(CSharpCodeWriter writer)
{
var baseTypeVisitor = new CSharpBaseTypeVisitor(writer, Context);
baseTypeVisitor.Accept(Tree.Chunks);
var baseType = baseTypeVisitor.CurrentBaseType ?? Host.DefaultBaseClass;
var baseTypes = string.IsNullOrEmpty(baseType) ? Enumerable.Empty<string>() : new string[] { baseType };
return writer.BuildClassDeclaration("public", Context.ClassName, baseTypes);
}
protected virtual void BuildConstructor(CSharpCodeWriter writer) protected virtual void BuildConstructor(CSharpCodeWriter writer)
{ {
writer.WriteLineHiddenDirective(); writer.WriteLineHiddenDirective();