FANDOM


Create a Collection class TemplateEdit

PrerequisitesEdit

  1. Setup the T4 Development Environment
  2. Create a project 
  3. Add a T4 Entity Model


Steps

  1. Add a .TT file
  2. Copy the code as described below

Code ExplanationEdit

  1. Reference the base template: T4UtilityBelt.Templates3.Template
  2. Add a volatileAssembly reference to T4UtilityBelt
  3. Add the include file reference
  4. The code loops through the Entities collection and creates one file per entity. Each file has a collection class.


T4 Code ExampleEdit

<# 
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 ExampleEdit

using System.Collections.ObjectModel;
using Conference.Core.BL.Entities;
namespace Conference.BL.Collections
{
     public partial class SessionEntityCollection : Collection<SessionEntity>
     {
     }
}

 

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.