Cheatography
https://cheatography.com
Cheat Sheet for Microsoft T4 Templates
T4 ExtensionsDevart T4 Editor | | Tangible Engineering T4 Editor | | Resharper T4 Extension | |
Microsoft Documentation on T4Overview of T4 | | Writing a T4 Template | | TextTransform.exe | |
Template HeaderDefine 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" #>
|
Control Blocks<#
for(int i = 0; i < 4; i++)
{#>
This is index <#= i+1 #>
<# }#>
|
| | Videos on T4 TemplatesC# Code Generation Using T4 Templates | | Code Generation with T4 Templates | |
Text Template Utility MethodsWriteLine("Some Text") | Write("Some Text") | PushIndent("\t") | ClearIndent() |
Class Feature Block<#+
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();
}
#>
|
|
Help Us Go Positive!
We offset our carbon usage with Ecologi. Click the link below to help us!
Created By
www.kellermansoftware.com
Metadata
Comments
No comments yet. Add yours below!
Add a Comment
More Cheat Sheets by GregFinzer