Tuesday, December 1, 2009

Code Generation

Someone suggested that I look at CodeDom, which is a .NET namespace. It allows you to describe code to generate in a precise, verbose way, that is considerably longer than the generated code. The main advantage, if you care, is you can have the same CodeDom code generate code for either VB.NET or C#. The downside of that is you cannot use any C#-isms.

T4 is a capability inside Visual Studio, a templated approach to code generation.

My eyes glazed over as I read it. I want code generation to be driven by meta-data. If the STATUS column on a table is a single character, translated at run-time to something readable, then I want to record that fact in a database table, so the translation can be done when the SQL is generated (or when the business object is populated from the SQL). I want to generate SQL by retrieving a table's columns from USER_TAB_COLUMNS and (optionally) joining to related tables as indicated when I detect foreign key relationships. Where does the generated code go? We have multiple targets and each has its own folder structure for the various entities and objects. That's all meta-data. A large part of the app will be making it easy to set that data.

Someone else suggested CodeSmith.

I should look over T4 and CodeSmith enough to have a glimmer about how they work. At worst, that will help inform my own custom coding.

No comments:

Post a Comment