Quick & Dirty CodeGen
I needed to get some code that would map an XML file to a database table. Not being particularily fond of doing it by hand, I whipped out this statement:
select '
if node.SelectSingleNode("' + column_name + '/text()") is not null:
row["' + column_name + '"] = node.SelectSingleNode("' + column_name + '/text()").Value
else:
row["' + column_name + '"] = DBNull.Value'
from information_schema.columns
where table_name = 'Content'
I am doing about 60% of my code gen with SQL and Regex, I think.
Comments
This is cool. I use SQL for all sorts of code gen too. It's also great for generating batch scripts, or generating SQL/DDL/DML.
I use it to create Active Record class, including everything...
And using the new XML features I can create a fully functional admin console GUI for web apps with a simple F5.
I've been told that I'm taking it too far, though I'm glad that I'm not alone on this.
I use a custom .Net app based on:
http://secretgeek.net/wscg.asp
For doing my lightweight code gen.
I extended it a bit to save snippets of code.
And that works wonders for me :)
Comment preview