c# - Using reflection for code gen? -
I am writing a console device to generate some C # code for objects in the class library. The best / easiest way I can actually generate a code is to use reflection after building the library. It works great, but it looks like a random way, because the generated code will be compiled with the library, after making a change, I will need to create a solution twice to achieve the final result. Some of these issues can be reduced with a script script, but it still looks like one
My question is, are there any top-level best practices for such things?
Did you consider using a T4 template to run the code generation? It seems that it is getting more publicity and attention now and now there is more help in VS02010.
This tutorial is centered on the database but it can give you some pointers: Apart from this, there was also recently Hanselminute on T4. Edit: Another great place is the T4 tag on the stack overflow:
Edit: (Asker, from new development)
According to VS 2012, T 4 now supports reflection on an active project in the same phase, that means you can make changes to your code, and the compiled output of the T4 template will reflect the latest version without the need for you to do the latest reflect / build phase . With this capability, I am marking it as an accepted answer.
Comments
Post a Comment