I was taking a stab at resolving issue 731, related to factoring the generated code to conform to our coding standards, and it occurred to me it would be much easier if I didn't have to cope with the T4 files - Visual Studio insists on doing silly things with them, like trying to execute them when I save. So I've prototyped a replacement template system; a proof of concept is attached to this email as a patch file.
Currently, the generator has a series of types that essentially constitute an object model for C# code. The idea behind the template implementation is to homogenize the access to that object model, treating it like a tree. The CodeObject interface -- which is quite poorly named, and suggestions for a better one are welcome -- does this. The appropriate CSharp* classes would implement CodeObject, which mandates a Name, Namespace and Content property. The first two should be self-explanatory. The last one is a bit unique. Content is a System.Object, which at runtime can be a scalar value or an IEnumerable<CodeModel>. More on this later.
The TemplateProcessor object is used to actually evaluate template replacements. It has a single processing method which is called with a CodeObject input. It understands the association between a concrete CodeObject type and the template via because the concrete type is decorated with a TemplateAttribute object that specifies the file name. TemplateProcessor does simple regular expression replacements for the <{name}> and <{namespace}> fields, but checks the actual type of the content field to see if it should be replaced as a simple scalar, or recursively as a list of children. In the recursive case, care is taken to preserve the text prefixing the <{content}> item and insert newlines as appropriate in order to generate clean code. Double-evaluation is also prevented.
In the prototype, I've implemented this pattern for enumerations. If you run the generator in the debugger, it will produce a bunch of source files for each enumeration under the appropriate Generated directory for each API.
Keep in mind this is only about ten minutes of work, so there are issues. I'm already a bit concerned about the strangeness of the Content property and the special-case handling. This system is very similar to the view object model we use for our tools at work -- all game content objects can be transformed, either via a default transformation or a custom one, into a view object (which is more akin to an interpretation of the content data than an actual UI view), which consists essentially of a value and some children. Content, in the template model I've built here, rolls value and children into one, and I'm not sure I'm happy with that.
-- jmp