Setting Properties

A code generator that generated the exact same code every time wouldn't be very useful (you might as well just paste in a saved code file, if that's what you want). CodeSmith Generator templates use properties to let you customize the generated code. When you open a template from Template Explorer, the template's property sheet shows you all of the properties that the template requires. You need to supply values for these properties before CodeSmith Generator can generate the code for you. The HashTable.cst template that we opened in the previous step requires four string properties (ClassName, ClassNamespace, ItemType, and KeyType) and one enumerated property (Accessibility). You can type any value you like for a string property; an enumerated property presents you with a drop-down list of choices when you click in it. For this first experiment, fill out the property sheet this way:

One of the best things about CodeSmith Generator is that properties can be based on many different types of metadata. For instance, you can create a property that presents a list of all of the tables in a database, letting the user choose a table when they're generating the code. You can learn more about this in the section on Driving Templates with Metadata.

You can also filter the properties that are shown in the property sheet, by typing the name of the property in the Filter Search Box located above the property sheet.

 

Next: Generating Code