I agree with the one poster that mentions creating a reusable framework to eliminate duplication. Don't use code generation as a fancy copy and paste alternative.
With that said, I have made good use of python to generate vb.net code. What I did was create a python script to interpret a mini-language that I created to simplify database table creation.
What the script does is interpret the mini-language and generate the SQL script files that in turn create the database tables. In addition, it also generates vb.net partial classes that map to the individual tables. These partial classes contain property names that map to the individual field names and are set to the correct data type.
What it allows me to do is quickly add tables or fields to tables (with proper foreign key relationships) and have the vb.net code to store the data generated automatically. I choose to generate partial classes because I can then simply replace the existing partial classes without effecting the rest of the structure.
It really is quite fancy. The nice thing about python is that I can easily add a new class definition to:
- Generate a different dialect of SQL (for example MySQL, oracle, postgressql, etc.
- Generate different code class (for example c#).
The mini-language definition is quite straight forward and is basically a bulleted list. it took me quite awhile to get the script right but it will save me considerable effort when the database schema changes - even if it is a single field addition. I just have to modify my mini-language file and run the script!