Razor Editor
The Razor Editor is where you will edit and test your Code Generation Templates.
The Editor also has a "Preview" tab that allow you to debug your templates.
The Razor Template Editor provides some simple syntax highlighting and highlights the Razor Code with a yellow background.
Each Razor Template is stored as a text file which allows them to be managed by Git or other source control tools.
Razor Template Properties
The Razor templates have a number of properties associated with them.
- File Name Template
- Generation Type
- Output
- Sample Code Element
File Name Template
This allows you so define what the name of the generated file will be. This file has a simple {{}} syntax to inject the name of the current element or model into the file name. This same syntax is also used for the directory folder names.
The follow values can be injected into the file/folder names:
- {{Solution.Name}}
- {{Diagram.Name}}
- {{Class.Name}}
- {{Interface.Name}}
- {{Element.Name}}
Examples:
{{Element.Name}}.cs for the Class named "Person" would create the filename "Person.cs"
{{Class.Name}} in a folder for the Class named "Person" would create the folder "Person"
Generation Type
This defines what type of element the code generator template works with.
The possible types are:
- Project
- Diagram
- Class
- Interface
- Class or Interface
- Enumeration
This allows you to help define when an template will be run.
When the Generator Type is set to Diagram, it will only be run once for that Diagram. For others Type like Class, the template will be run for every Class in the diagram.
The Diagram or Project Types are useful when you need to create a singular file for the output. In the supplied AngularJs generator the app.js.razor template is set to Diagram so that it only gets created once for the project.
Output
When an template is run this parameter helps to define were the output of the template will go.
The options are:
- File
- Macro
- Snipit
File
This will write the generated code to the file system with name defined in the File Name Template property
Macro
These will not be executed during code generation. The macro's can run manually via the preview tab.
SnipIt
The output from these templates will be displayed in the SnipIt window.