Frequently asked questions
Templates
How do I add comments to a template?
Surround them with <%-- and --%>. See Including comments.
How do I create a property with a drop-down list of values?
Define an enumeration in a script block and use it as the property type. See Declaring an enumerated property.
How do I stop ASP.NET tags from confusing my templates?
Escape them. See Escaping ASP.NET tags.
How do I declare a constant in a template?
Declare it inside a <script runat="template"> block:
<script runat="template">
private const string MY_CONST = "example";
</script>
How do I debug my templates?
Compile your templates in debug mode and set breakpoints in them.
How do I add a property that lets the user select a folder?
Decorate the property with the FolderNameEditor attribute. See FileNameEditor.
How do I use sub-templates?
Generator has a full API for sub-templates.
What if my template contains non-ASCII characters?
Set the encoding with the ResponseEncoding attribute of the CodeTemplate directive.
Which assemblies and namespaces does every template load by default?
| Assemblies | Namespaces |
|---|---|
System |
System |
System.Core |
System.Data |
System.Xml |
System.Diagnostics |
System.Data |
System.ComponentModel |
System.Drawing |
Microsoft.VisualBasic |
System.Design |
CodeSmith.Engine |
Microsoft.VisualBasic |
|
System.Windows.Forms |
|
CodeSmith.Engine |
|
CodeSmith.Core |
SchemaExplorer
Can I tell whether a column is an identity column?
Yes. Use the CS_IsIdentity extended property.
Can I get a column's default value?
Yes. Use the CS_Default extended property:
<%
foreach (ColumnSchema cs in SourceTable.Columns)
{
if (cs.ExtendedProperties["CS_Default"] != null)
{
Response.WriteLine(cs.ExtendedProperties["CS_Default"].Value);
}
}
%>
How do I see the source definition of a view or stored procedure?
Use the CommandText property of a CommandSchema object, or the ViewText property of a ViewSchema object.
How do I list a stored procedure's input and output parameters?
The CommandSchema object has collections for both input and output parameters.