执行子模板
Main.cst
<%@ Template Language="C#" TargetLanguage="Text" %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Import Namespace="SchemaExplorer" %>
<%@ Property Name="SourceDB" Type="DatabaseSchema" Optional="False" %>
<script runat="template">
public void RenderChild1()
{
CodeTemplateCompiler compiler = new CodeTemplateCompiler(".\\Child.cst");
compiler.Compile();
if (compiler.Errors.Count == 0)
{
CodeTemplate template = compiler.CreateInstance();
//DatabaseSchema SourceDB = new DatabaseSchema(new MySQLSchemaProvider(), @"Data Source=127.0.0.1;User Id=root;Password=xYi7sR2Ivc;Database=meshop_www;Port=33306;");
TableSchema table = SourceDB.Tables["user_info"];
template.SetProperty("SourceTable", table);
//template.Render(Response);
template.RenderToFile(".\\"+table.Name+".cs",true);
}
else
{
for (int i = 0; i < compiler.Errors.Count; i++)
{
Console.Error.WriteLine(compiler.Errors[i].ToString());
}
}
}
</script>
<%RenderChild1(); %>
Child.cst
<%@ Template Language="C#" TargetLanguage="Text" %>
<%@ Property Name="SourceTable" Type="TableSchema" %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Import Namespace="SchemaExplorer" %>
<script runat="template">
public void Output()
{
foreach(ColumnSchema column in SourceTable.Columns)
{
Response.WriteLine(column.Name);
}
}
</script>
<% Output(); %>