Folks, A few years ago I wrote (or rewrote) a quite large WPF Desktop app,
it's my "hobby app" like a lot of us have. It maintains RDB tables of the
music, books, video, etc in the household. This app was started in Access
2.0 back in 1992 and I think it's gone through at least 6 generations of
rewrites since then due to the ever-changing languages, platforms, kits and
frameworks. The last incarnation of the app took several months of spare
time to get into a good working condition, but by the time it was nearly
finished it was obsolete.

A few months ago I started a new rewrite using the latest Entity Framework,
lots of WPF binding and recent groovy techniques and tools. 14 underlying
tables are editable, and by some unimaginable effort in previous years I
managed to hand code (with lots of copy and paste) grids and dialogs for
all of the tables, all similar but slightly different.

In the latest rewrite I just couldn't face migrating or writing 14 sets of
grids and editors again, so I decided to use T4 templates to generate it
all. I'm really happy with the results and this post is basically just a
reminder that in my opinion, good old fashioned code generation still has a
place in the modern world.

I composed an XML document describing the attributes of every table and
field and then used TT files to generate the grid xaml, grid code, dialog
xaml, dialog code, ICommand definitions and handlers, controllers, and
validation. It's a slog to get the infrastructure started, but once it's
going it just spits out reliable working code like confetti. As you make
improvements in the templates it's most gratifying to see the benefits
magnified out over the generated code.

I find the T4 Toolkit a bit fiddly to use and generate multiple files, so I
found this:

https://github.com/damieng/DamienGKit

I'm impressed by this concise and convenient utility that helps you spit
out multiple files from a single template.

Greg K

Reply via email to