I used two CodeSmith templates within minutes of each other yesterday and was–as usual–struck by how productive it is. I continue to seek new uses of CodeSmith in my applications to add to my personal CodeSmith Library, but the library has not been growing as I’d like it to. I will stay in the hunt.
The templates I used the other day that inspired this post were to 1) create an enumerator from a table and 2) take an ADO.NET 2.0 DataTable, sort it in a DataView and spit out the sorted DataTable. Yes, other ways to do the latter, particularly in .NET 2.0, but that’s another post. Both templates are in my CodeSmith Library.
Here you see that the enum name is entered (ResourceArea), the SQL table field name for the enumerator element (ResourceAreaCode), and the SQL ID field for the value (ResourceAreaID.) And Bam!
The next template generates more code, using a “z_resources” table (a temporary ‘select * into z_resources’ table created in 5 seconds for this template’s use) with a Root Table name. A Root Name is one of the important points in code generation I’ve found, that is to name objects with a standard naming convention. Here, the Root Name of this table is “Resources” and is used to generate _dtResources, dtResourcesDataTable, CreateSortedResources, etc.