<#@ template debug="true" hostSpecific="true" #>
<#@ output extension=".log" #>
<#@ Assembly Name="System.Core.dll" #>
<#@ Assembly Name="System.Windows.Forms.dll" #>
<#@ Assembly Name="System.Xml.dll" #>
<#@ Assembly Name="System.Xml.Linq.dll" #>
<#@ import namespace="System" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Diagnostics" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Xml" #>
<#@ import namespace="System.Xml.Linq" #>
<#@ import namespace="System.Collections" #>
<#@ import namespace="System.Collections.Generic" #>
<#
string currPath = Path.GetDirectoryName(Host.TemplateFile);
XDocument xd = XDocument.Load(Path.Combine(currPath, "marathon.xml"));
foreach (var t in xd.Root.Elements()) {
string tableName = t.Attribute("id").Value;
#>
using System.ComponentModel.DataAnnotations;
public class <#= tableName #>
{
<#
foreach (var c in t.Elements()) {
string name = c.Attribute("name").Value;
string type = c.Attribute("datatype").Value;
bool isPK = c.Attribute("pkey") != null;
if (isPK) {
#>
[Key]
<#
}
#>
public <#= type #> <#= name #> { get; set; }
<#
}
#>
}
<#
string relativeOutputFilePath = "Code\\" + tableName + ".cs";
string outputFilePath = Path.Combine(currPath, relativeOutputFilePath);
TemplateHelper.WriteTemplateOutputToFile(outputFilePath, GenerationEnvironment);
}
#>
<#+
//REF: http://bit.ly/X9wTu0
public class TemplateHelper
{
public static void WriteTemplateOutputToFile(
string outputFilePath,
System.Text.StringBuilder genEnvironment)
{
System.IO.File.WriteAllText(outputFilePath, genEnvironment.ToString());
genEnvironment.Clear();
}
}
#>