T4UtilityBelt EntityClassTemplate

Create an entity class template

 * 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 from the Example

T4 Code Example
<# var version = "0.1"; inherits="T4UtilityBelt.Templates3.Template"#> <#@ output extension = ".txt" #> <#@ VolatileAssembly Processor="VolatileAssemblyProcessor" name="T4UtilityBelt" #> <#@ include file="$(SolutionDir)\TealightV5\Conference.Designs\Entities.ttinclude" #> <# this.EntityPropertyRenderers.Add(new RenderParentOne); this.EntityPropertyRenderers.Add(new RenderParentMany); this.EntityPropertyRenderers.Add(new RenderKeyProperty); this.EntityPropertyRenderers.Add(new RenderProperty); foreach(Entity entity in Entities) { StartNewFile(entity.Name + "Entity.cs"); WriteAutoGeneratedComment(version); #> using System; using System.Collections.Generic; using System.Xml.Serialization; using Cirrious.MvvmCross.Plugins.Sqlite; using <#=Namespace#>.Core.Dal; using TeaLightV5.Foundation.BL; using TeaLightV5.Foundation.Sal.Interfaces; amespace <#=Namespace#>.Core.BL.Entities { public partial class <#=entity.Name#>Entity : Entity, ISyncableEntity {        #region Constructor public <#=entity.Name#>Entity { <# foreach(Property property in entity.Properties) { if (!string.IsNullOrEmpty(property.DefaultString)) { #> <#=property.Name#> = <#=property.DefaultString#>; <#                } } #>         }          #endregion #region Fields <# RenderEntityProperties(entity); } } <# } ProcessFiles; #> <#+ public class RenderKeyProperty : T4UtilityBelt.EntityModels3.Renderers.Renderer { public override void Render(T4UtilityBelt.EntityModels3.KeyProperty property) {    } } #> <#+ public class RenderProperty : T4UtilityBelt.EntityModels3.Renderers.Renderer { public override void Render(T4UtilityBelt.EntityModels3.Property property) {       string propertyName = property.Name; string propertyType = property.PropertyType; public <#=propertyType#> <#=propertyName#> { get; set; } <#+    } } #> <#+ public class RenderParentOne : T4UtilityBelt.EntityModels3.Renderers.Renderer { public override void Render(T4UtilityBelt.EntityModels3.ParentOne property) { string propertyType = property.PropertyType; if (property.PropertyType == "Guid" || property.PropertyType == "Guid?") { propertyType = "string"; }        public <#=propertyType#> <#=property.Name#> { get; set; } [XmlIgnore] [Ignore] public <#=property.ToName#>Entity <#=property.Association#> {            get {                return <#=property.Entity.Name#>Repository.Get<#=property.ToName#>(this); }        }  <#+     } } #> <#+ public class RenderParentMany : T4UtilityBelt.EntityModels3.Renderers.Renderer { public override void Render(T4UtilityBelt.EntityModels3.ParentMany property) {        [Ignore] public IEnumerable<<#=property.PropertyType#>> <#=property.ToEntity.PluralName#> {            get {                return <#=property.Entity.Name#>Repository.Get<#=property.ToEntity.PluralName#>(this); }        }  <#+     } } #>
 * 1) ><#@ template language="C#" debug="true" hostspecific="true"
 * 1) > #endregion
 * 1) > [XmlElement("<#=propertyName#>")]
 * 1) > [XmlElement("<#=property.Name#>Entity")]
 * 1) > [XmlIgnore]

Generated Code Example
using System; using System.Collections.Generic; using System.Xml.Serialization; using Cirrious.MvvmCross.Plugins.Sqlite; using Conference.Core.Dal; using TeaLightV5.Foundation.BL; using TeaLightV5.Foundation.Sal.Interfaces; namespace Conference.Core.BL.Entities {    public partial class SessionEntity : Entity, ISyncableEntity {        #region Constructor public SessionEntity {        }          #endregion #region Fields [XmlElement("Created")] public DateTime Created { get; set; } [XmlElement("CreatedBy")] public string CreatedBy { get; set; } [XmlElement("Modified")] public DateTime Modified { get; set; } [XmlElement("ModifiedBy")] public string ModifiedBy { get; set; } [XmlElement("Name")] public string Name { get; set; } #endregion } }