The CodeTemplate object
Every CodeSmith Generator template is compiled into a class that inherits from CodeSmith.Engine.CodeTemplate (or from another class you name in the Inherits attribute). The CodeTemplate object represents your template while Generator processes it, so you can override its members in a <script runat="template"> block or a code-behind file to take part in the generation process.
Members covered in these docs
| Member | Kind | What it does |
|---|---|---|
GetFileName |
Method you override | Supplies the default output file name. |
ParseDefaultValue |
Method you override | Converts a property's Default string into a value. |
Render |
Method you override | Produces the template's output. |
GetCustomValidationErrors |
Method you override | Returns your own validation errors, which stop generation. |
OnInit, OnPreRender, OnPostRender, OnPropertyChanged |
Events | Let you run code at points in the template processing cycle. |
Response |
Property | The output stream. Write to it directly or add more output destinations. |
Progress |
Property | Controls the progress bar shown while the template generates. |
CodeTemplateInfo |
Property | Information about the template file. |
Create<T>, CopyPropertiesTo, RenderToFile |
Methods | Create, configure and render sub-templates from a master template. |
Overriding ParseDefaultValue
Sometimes a property needs a default value that can't be converted automatically from a string. In that case, override the ParseDefaultValue method to parse the Default string from the template and assign the value to the property yourself.
Generator calls ParseDefaultValue for each property in the template and passes it the property and the default value string. In your override, handle the properties you care about and pass all other properties on to the base ParseDefaultValue method.