Frequently Asked Questions

Q. How can I add comments to my templates?

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

Q. How can I create a property that has a dropdown of values to choose from?

A. Use a script block to define an enumerated property.

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

A. Properly escape the ASP.NET tags.

Q. How can I declare a constant in my template?

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

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

Q. How can I debug my templates?

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

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

A. Decorate the property with the FolderNameEditor attribute.

Q. How can I use sub-templates?

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

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

A.

Assemblies: mscorlib, System, System.Xml, System.Data, System.Drawing, Microsoft.VisualBasic, System.Windows.Forms, CodeSmith.Engine

Namespaces: System, System.Data, System.Diagnostics, System.ComponentModel, Microsoft.VisualBasic, CodeSmith.Engine

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

A. Yes. Use the CS_IsIdentity property.

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

A. 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);
        }
    }
    %>

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

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

Q. What if my template contains non-ASCII characters?

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