CodeSmith Generator samples

When you install CodeSmith Generator, you also get a set of samples in your Documents folder:

Samples Location What they're for
Sample templates Documents\CodeSmith Generator\Samples\<VERSION>\Templates Load them in Generator and generate code.
Sample projects Documents\CodeSmith Generator\Samples\<VERSION>\Projects See how to extend and customize Generator.

The sample templates are also available in the CodeSmith Generator Templates repository on GitHub.

Sample templates

Generator ships with a complete set of templates to get you up and running quickly, including ActiveSnippet, database and example templates.

Note

The framework templates (PLINQO and CSLA) aren't installed with Generator. The samples' Templates\Frameworks folder contains only a readme that points to the releases page on GitHub, where you can download them.

ActiveSnippet templates

ActiveSnippets cut down the time it takes to write common code, and any template can be used as an ActiveSnippet. The included ActiveSnippets create custom events and exceptions, and generate an enumeration or properties from database metadata.

Database templates

These templates help you create business objects, document your database, script your table data, and create or call stored procedures.

Template What it does
Business Object Quickly creates an entity for your project. Many developers also use it as the starting point for their own POCO (plain old CLR object), data transfer object or domain class templates.
Script Table Data and Extended Properties Generates a SQL script you can use to migrate data between database servers, or to import existing data into new databases.
DbDocumenter Creates a formatted HTML document of your entire database.
Stored Procedures Creates insert, update, delete and select stored procedures for a database table. Everything is configurable.
Command Wrapper Creates a wrapper around any SQL stored procedure or function. Call Execute() to run it and get back a strongly typed object or result. Use it with the Stored Procedures template to get data from your database quickly.

Example templates

These templates show how to use various Generator features in your own templates.

Folder What it shows
BasicSamples Master templates, partial templates and LINQ to Objects in templates.
Maps How and when to use Generator maps.
Merge The PreserveRegions and InsertRegion merge strategies across different file types and languages.
Xml Generating from an XML data source with the XmlProperty directive.

Sample projects

Project What it contains
SchemaProvider source code Source code for the schema providers, in the CSharp folder.
BaseTemplates Source code for the CodeSmith.BaseTemplates classes.
ConsoleSamples Samples for the console application.
VSIntegrationSample Uses the Visual Studio integration to simulate generics with a Generator project.
CustomPropertiesSample Source code for the CodeSmith.CustomProperties classes.
APISample Shows how to use the Generator API.