Templates

Description

Templates contain the information that is used to generate the code.

Template Information
Name Description Sample
Name Name of the template. C# Class Template
File Name Name of the file that will be created or updated when you generate the code. You can inject in this field the entity metadata to generate the file name dynamically. {{model.Name}}.cs
Description Description of the template. C# Class Template
Folder Name of the folder where the file will be saved. If the Subfolder is not empty, the file will be saved inside the Subfolder. src -> Domain -> Entities
Subfolder If this value is not empty this folder will be inside the folder and the file will be saved inside this Subfolder. You can inject in this field the entity metadata to generate the Subfolder name dynamically. {{model.Package}}
Action Determine if the file name will be created or updated. The values are: Create, Update and Append. Create
Template Text A template text consists of a piece of text that expresses the desired generated code following the DotLiquid syntax. This syntax allows you to write some logic that can add conditions and loops while accessing the Entity data. There is a special variable called model which represents the instance of the Entity being injected at code generation time.
public class {{entity.Name}}
{
{%- for p in model.Properties -%}
public {{ p.VarType }} {{ p.Name }} { get; set; }
{%- endfor -%}
}

Accessing Entity Metadata

There is a special variable called model which represents the instance of the Entity being injected at code generation time.

Entity Atributte Description How to get the value
Name Name of the entity {{model.Name}}
Description Description of the entity {{model.Description}}
Properties Entity's properties {%- for p in model.Properties -%}
{%- endfor -%}
Package Package that the entity belongs to. A package is a container folder that can be used as Subfolder for the template. It adds another level of separation for the cases where there are many entities in the same project {{model.Package}}
ProjectPackage Name of project's package {{model.ProjectPackage}}
TableName SQLDatabase table corresponding to this entity if using a Database to be stored {{ model.TableName}}
CurrentTime Date Time at code generation time {{model.CurrentTime}}
Guid A Guid value {{model.Guid}}
BinaryDateTime Current DateTime in binary format (a long numeric value) {{model.BinaryDateTime}}

Entity Properties

Usually accessed by iterating through the Properties attribute in a for loop

{%- for p in model.Properties -%}    
{%- endfor -%}

Accessing Property Values
Property Atributte Description How to get the value
Name Name of the property {{p.Name}}
Description Description of the property {{p.Description}}
ColumnName Column Name for the table, used if generating SQL statements such as CREATE TABLE {{p.ColumnName}}
VarType Variable type, this will depend on the programming language i.e int, string, etc {{p.VarType}}
IsPrimaryKey Determines whether the Property is primary key, used if generating SQL statements such as CREATE TABLE {{p.IsPrimaryKey}}
DbType Database column type for this property, it will depend on the specific SQL flavour, used if generating SQL statements such as CREATE TABLE {{p.DbType}}
Required Determines whether this Property is required, this will influence the template i.e adding [Required] in C# {{p.Required}}
List Determines whether this Property is present in the “List” view, this is helpful when creating views for “List”, it can be used to filter out Properties to get only the relevant ones, i.e hiding Id from the “List” view {{p.List}}
Create Determines whether this Property is present in the “Create” view, this is helpful when creating separate views for “Create”, it can be used to filter out Properties to get only the relevant ones. {{p.Create}}
Edit Determines whether this Property is present in the “Edit” view, this is helpful when creating separate views for “Create” and “Edit”, it can be used to filter out Properties to get only the relevant ones, i.e hiding Id from the “Edit” view {{p.Edit}}
Filter Determines whether this Property is present in the “Filter” view, meaning you can filter by this property {{p.Filter}}
ColumnType Database column kind, this is to distinguish between Key columns and regular columns. Values: Column, Identity, PrimaryKey, ForeignKey {{p.ColumnType}}
VisualType Visual component to be used if this Property is present in either “Create” or “Edit” views. Values: Text, Select, Checkbox, RadioButton, Hidden, Textarea, DateTime, MultipleSelect {{p.VisualType}}

The properties Name, Description, ColumnName and VarType are string values and you usually will get their values. Also you can apply filters to their values or use them with if or case statement.

public class {{model.Name}} : BaseEntity, IAggregateRoot
{
{%- for p in model.Properties -%}
{%- if p.Name == 'Id' -%}{%- continue -%}{%- endif -%}
    ...
{%- endfor -%}
}

The properties IsPrimaryKey, Required, List, Create, Edit and Filter are boolean values and you usually will use them with the if statement.

{%- for p in model.Properties -%}   

    {%- if p.List -%}...{%- endif -%}

    {%- if p.Create -%}...{%- endif -%}

{%- endfor -%}

The properties ColumnType and VisualType are string values and have predefined values and you can use them with if statement or case statement.

{%- for p in model.Properties -%}   

    {%- if p.ColumnType == 'Identity' -%}...{%- endif -%}

    {%- if p.VisualType == 'Select'  -%}...{%- endif -%}

{%- endfor -%}
© DynamoCode.