Generate code

When you've set the template's properties, click Generate at the bottom of the property sheet. CodeSmith Generator combines your property values with the template and shows the generated code in an output window.

In the output window you can:

  • edit the generated code by typing in it,
  • click Save to File to save it (the template names the file after the class, OrderNotFoundException.cs), or
  • click Copy to Clipboard to copy it.

The output is a complete OrderNotFoundException class in the Contoso.Orders namespace: the standard exception constructors, constructors that take an orderId, a read-only OrderId property, serialization support, and a ToString() override that includes the order ID in the message. An experienced C# developer could write all of it by hand, but there's no need. This is the kind of routine work Generator is built for, so you can spend your time spotting patterns in your code, turning them into templates, and reusing them.

Try changing a property, such as adding another entry to Arguments (for example CustomerName=string), and click Generate again to see the class update.

Tip

To run templates from anywhere, including your build, save your property values in a Generator project.

Next: Inspect the template