Advanced Topics

These pages cover what you need once your CodeSmith Generator templates are part of a real project: regenerating code without losing your changes, reusing helper libraries, extending the property grid and SchemaExplorer, and getting database connections to work.

Generating and regenerating code

Page What it covers
Merge strategies Regenerate part of a file and keep the rest, with the InsertRegion, PreserveRegions and InsertClass merge strategies or your own.
Active vs. passive generation Three ways to keep hand-written code alongside generated code: inheritance, partial classes and merge strategies.
Auto-executing generated SQL scripts Run a generated SQL script against the database as soon as the template finishes.
Template caching How Generator reuses compiled templates, and how to clear the cache.
Version control support How Generator avoids needless check-outs and works with your source control tools.

Extending templates

Page What it covers
CodeSmith.BaseTemplates Base classes and utilities for templates: OutputFileCodeTemplate, SqlCodeTemplate, StringUtil and ScriptUtility.
Using CodeSmith.CustomProperties Ready-made property editors, such as a file picker, for your template properties.
Building a custom UITypeEditor Write your own property editor, using a drop-down list of table names as the example.

Working with databases

Page What it covers
Setting up a DataDirectory for connection strings Use the DataDirectory placeholder in connection strings and change the folder it points to.
Configuring and troubleshooting a schema provider Connection strings, provider options, and fixes for the Oracle, MySQL, SQLite and PostgreSQL providers.
Building a custom schema provider Expose your own data source to SchemaExplorer by implementing IDbSchemaProvider.