So over the last couple weeks I’ve spent a grand total of about 30 hours ironing out what I need from a code generator (screen shot).  It’s not as flexible as CodeSmith is (i.e., no templates), but it does what I want, and it does it every time.  Maybe someday after I add a few more “desired” features and work out more of the kinks, I’ll post the app and/or source up here.  (Translation: You’ll be lucky if you ever see it.)  The source isn’t pretty — it’s just basically a top down application that retrieves schema info from the database and does its best to turn that into VB code.

Anyway, it’s pretty basic.  What it boils down to is that you specify a SQL connection string and it generates the BOL and DAL code as well as the SQL stored procedures need to operate.  The generated code comes from a “template” that I built based on code from other generators, and code I hand-wrote that I wished had been generated.  There was a project at work where, over time, I ended up spending probably 30 hours just on this could-be-generated code alone.  Now that code comes out in about 10 seconds.  Obviously I still have code to write, but the tedious stuff is done.  Here is a brief list of what my code generator does and does not do.

Current Features

  • Generate BOL code (Base and Safe classes)
  • Generate DAL code (Base and Safe classes)
  • Generate SQL stored procedure script
  • Allows for saving and retrieving project settings to a “.genproj” file (I made that extension up myself.  What do you think?)

Possible Future Features

  • Generate Base and Safe classes for the test project (NUnit tests)
  • A simple WebForms data editing tool
  • A simple WinForms data editing tool
  • More options in the UI to select which items to generate on a table by table basis
  • Support for SQL Server views (in addition to tables)
  • Other features that I should have written down, but have since forgotten

Now that I have this code generator complete (with the exception of detailed testing), a friend sent me a link to this blog entry on his site.  It’s about CodeDom.  His blog links to this article on DevX.

I should have researched this first!

It looks like it would have been much more cumbersome to build my generator, but I could have built in to generate code in any language, and even compile it on the fly!  Hmmm.  Should I go back to the drawing board?  I probably should, but doubt that I will…

If you have any feature suggestions for my code generator, list them here as comments, and I’ll consider adding them.  My goal isn’t for this to become the super-awesome-generates-code-for-every-situation code generator.  I just want it to save me time on the normal, tedious, boring, everyday stuff!