CodeSmith.BaseTemplates

CodeSmith Generator includes CodeSmith.BaseTemplates, an assembly of base classes and utilities for your templates. It's installed in the AddIns folder of the Generator installation folder, so templates can reference it by name, and its source code is in the samples, in Documents\CodeSmith Generator\Samples\v8.5\Projects\CSharp\BaseTemplates. You can use the source as a starting point for base classes of your own.

Base classes

To use a base class, reference the assembly and name the class in the Inherits attribute of the CodeTemplate directive:

<%@ CodeTemplate Language="C#" TargetLanguage="T-SQL" Inherits="CodeSmith.BaseTemplates.SqlCodeTemplate" %>
<%@ Assembly Name="CodeSmith.BaseTemplates" %>
Class What it adds
OutputFileCodeTemplate An OutputFile property; the template saves its output to that file.
SqlCodeTemplate Helper methods for generating code from database columns. Inherits from OutputFileCodeTemplate.

Utility classes

Class What it does
ScriptUtility Runs SQL scripts against a database. Part of CodeSmith.BaseTemplates.
StringUtil Pluralizes, singularizes and changes the case of strings. Part of the CodeSmith.Engine assembly, which every template can use.

To use a utility class, reference its assembly and import its namespace.