Cheat Sheet for Microsoft T4 Templates
|
Devart T4 Editor
|
|
|
Tangible Engineering T4 Editor
|
|
|
Resharper T4 Extension
|
|
Overview of T4
|
|
|
Writing a T4 Template
|
|
|
TextTransform.exe
|
|
Define Language and Debugging
|
<#@ template debug="false" hostspecific="true" language="C#" #> |
|
Define File Extension
|
<#@ output extension=".cs" #> |
|
Reference Built In Assembly
|
<#@ assembly name="System.Core" #> |
|
Reference External Assembly
|
<#@ assembly name="$(projectDir)\Assemblies\KellermanSoftware.NET-Code-Generator-Logic.dll" #> |
|
Include Another Template
|
<#@ include file="$(projectDir)\Includes\CSharpHelper.tt" #> |
<#
for(int i = 0; i < 4; i++)
{#>
This is index <#= i+1 #>
<# }#>
|
C# Code Generation Using T4 Templates
|
|
|
Code Generation with T4 Templates
|
|
WriteLine("Some Text")
|
|
Write("Some Text")
|
|
PushIndent("\t")
|
|
ClearIndent()
|
<#+
private string GetTemplateDirectory()
{
return Path.GetDirectoryName(Host.TemplateFile);
}
private void SaveOutput(string outputFileName, string subDirectory= "") {
string templateDirectory = GetTemplateDirectory();
if (!string.IsNullOrEmpty(subDirectory))
{
templateDirectory = Path.Combine(templateDirectory, subDirectory);
}
string outputFilePath = Path.Combine(templateDirectory, outputFileName);
if (!Directory.Exists(templateDirectory))
{
Directory.CreateDirectory(templateDirectory);
}
File.WriteAllText(outputFilePath, this.GenerationEnvironment.ToString());
this.GenerationEnvironment.Clear();
}
#>
No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.