September 2004 - Posts

If you are new to code generation (even if you are not!) you need to get a copy of CodeSmith 2.6.  This app is the cats meow when it comes to templated code generation.  Eric Smith has really out done himself (is it really just one guy??).  Here are the features he listed in his release email:

- Syntax highlighting of both template and target languages.
- Much improved Visual Studio .NET custom tool.
- Outlining support.
- Line modification markers.
- CodeSmith Studio is now a single instance application.
- Improved compiler and template execution performance.
- Better Unicode support.
- Tons of other minor improvements and bug fixes.

He left out many more, but my favorite has got to be the “Template Code Expansion”.  Imagine an ASP 3.0 page with code and HTML intermingled.  Press Ctrl+Shift+M and watch the code collapse into hidden regions just like ASP.Net.  Very cool, and CodeSmith supports code behind as well.  As matter of fact, CodeSmith allows you take advantage of the full .NET framework to help you generate _YOUR_ code. 

Think about what ASP.Net has done for generating HTML?  Sure you could write that HTML by hand, but it really gets powerful when you can generate an HTML table row for each row in a table.  CodeSmith brings this same paradigm to code generation.

Nothing is cooler than code that writes code, and CodeSmith is the king of code generation.  Watch out for tips on how I use CodeSmith to help me get my projects done…

A buddy of mine pointed me to a great article on writing cool CodeSmith templates:
http://msdn.microsoft.com/library/en-us/dnhcvs04/html/vs04e5.asp

The author does a great job of covering the basics, and then gets into more complicated issues such as sub templates and custom property editors (like for picking a file using an OpenFile dialog box instead of requiring the user to type in the path to a file).

Very cool read.

with 0 Comments