Create a Collection class Template[]
Prerequisites[]
- Setup the T4 Development Environment
- Create a project
- Add a T4 Entity Model
Steps
- Add a .TT file
- Copy the code as described below
Code Explanation[]
- Reference the base template: T4UtilityBelt.Templates3.Template
- Add a volatileAssembly reference to T4UtilityBelt
- Add the include file reference
- The code loops through the Entities collection and creates one file per entity. Each file has a collection class.
T4 Code Example[]
<#
var version = "0.1";
#>
<#@ template language="C#" debug="true" hostspecific="true"
inherits="T4UtilityBelt.Templates3.Template" #>
<#@ output extension = ".txt" #>
<#@ VolatileAssembly Processor="VolatileAssemblyProcessor"
name="T4UtilityBelt" #>
<#@ include file="$(SolutionDir)\TealightV5\Conference.Designs\Entities.ttinclude" #>
<#
foreach(Entity entity in Entities)
{
StartNewFile(entity.Name + "EntityCollection.cs");
WriteAutoGeneratedComment(version);
#>
using System.Collections.ObjectModel;
using <#=Namespace#>.Core.BL.Entities;
namespace <#=Namespace#>.BL.Collections
{
public partial class <#=entity.Name#>EntityCollection
: Collection<<#=entity.Name#>Entity>
{
}
}
<#
}
ProcessFiles();
#>
Generated Code Example[]
using System.Collections.ObjectModel; using Conference.Core.BL.Entities; namespace Conference.BL.Collections { public partial class SessionEntityCollection : Collection<SessionEntity> { } }