Frequently Asked Questions

How can I add comments to my templates?

Template comments can be added using the <%- -%>tokens.

How can I create a property that has a drop-down of values to choose from?

Use a script block to define an enumerated property.

How can I prevent ASP.NET tags from confusing my templates?

Properly escape them using ASP.NET tags.

How can I declare a constant in my template?

Constants must be declared inside <script runat="template"> tags.

<script runat="template">
private const string MY_CONST = "example";
</script>

How can I debug my templates?

You can compile your templates in debug mode and set breakpoints in them.

How can I add a property that lets me select a folder?

Decorate the property with the FolderNameEditor attribute.

How can I use sub-templates?

CodeSmith Generator includes a full API to let you make use of sub-templates.

What assemblies and namespaces are loaded by default into a template?

Assemblies:

  • System
  • System.Core
  • System.Xml
  • System.Data
  • System.Drawing
  • System.Design
  • Microsoft.VisualBasic
  • System.Windows.Forms
  • CodeSmith.Engine
  • CodeSmith.Core

Namespaces:

  • System
  • System.Data
  • System.Diagnostics
  • System.ComponentModel
  • Microsoft.VisualBasic
  • CodeSmith.Engine

Is it possible to determine whether a column is an identity column using SchemaExplorer?

Yes, use the CS_IsIdentity property.

Is it possible to determine a column's default value using SchemaExplorer?

Yes, use the CS_Default property.

    <%
    foreach(ColumnSchema cs in SourceTable.Columns)
    {
        if (cs.ExtendedProperties["CS_Default"] != null)
        {
            Response.WriteLine(cs.ExtendedProperties["CS_Default"].Value);
        }
    }
    %>

How can I view the source definition of my view or stored procedure.

You can use the CommandSchema objects CommandText property or the ViewSchema objects ViewText property to view the source definition.

How can I enumerate the input and output parameters of a stored procedure using SchemaExplorer?

The CommandSchema object contains both input and output parameter collections which can be used to read these parameters.

What if my template contains non-ASCII characters?

You can use the ResponseEncoding attribute of the CodeTemplate directive to set the encoding for the template.