Twin Cities Code Camp

Jon Stonecash

Insane Code Generation

by Jon Stonecash

Mon, Oct 01, 2007
Room:
Time: 0:00

There are two primary ways of doing code generation: one, using code generation mechanisms such as "wizards" that someone else provides and, two, creating your own code generation templates. Writing your own code generation templates is coding, pure and simple (well perhaps not so simple). I am going to show you how to code templates using XML/XSLT, CodeSmith, MyGeneration, and (maybe) Orcas Software Factories. This will include a lot of code from templates that I have written (will write) for generating CSLA applications. One of the problems in generating code is how to extend the generated functionality. No matter how cleverly you code the code generation templates, there will always be some functionality that makes more sense to generate by hand. I will take a look at three different approaches to how to add that functionality to the generated code: using partial classes, using inheritance, and using delegates. Unit testing is one very important factor in wanting to extend to extend the generated code. I will cover some ways to structure the code, generated and hand-crafted, to support unit testing.


About the Author

Jon Stonecash is a Senior Consultant at Magenic. Jon Stonecash has worked in software development for much longer than he would like to admit. In that time Jon has had the opportunity to make most of the serious software development mistakes at least once. He has programmed in over a dozen languages including several different assembly languages, Fortran, COBOL, SNOBOL, classic Visual Basic, VB.NET, and C#. He has survived the structured programming revolution and the object-oriented revolutions (having inexplicably missed out on the sexual revolution). Jon's software development activities have included the development of operating systems, scientific and engineering applications, and enterprise systems. He has worked in every phase of software development from the initial specification of requirements through to customer support. Along the way, he picked up a BS in Mathematics and an MBA. He still has hopes of finding something that he can be reasonably good at. His long term interests center about databases and the aspects of the application that handle data access and business logic. He is also interested in the tools and processes that assist the development process. Jon can be reached at jons@magenic.com.

Links