Robert McLaws: FunWithCoding.NET

Public Shared Function BrainDump(ByVal dotNet As String) As [Value]


<script type="text/javascript"><!-- google_ad_client = "pub-4330602465258980"; google_hints = "ASP.NET, VB.NET, C#, C#.NET, WindowsForms, .NET Framework, VS2005, Visual Studio, XAML, WinFX, Windows Workflow, WPF, WCF, Atlas, NetFX3, Visual Studio Orcas"; google_ad_width = 120; google_ad_height = 240; google_ad_format = "120x240_as"; google_ad_type = "text_image"; google_ad_channel ="4997399242"; google_color_border = "B6C9E7"; google_color_bg = "EFEFEF"; google_color_link = "0000FF"; google_color_text = "000000"; google_color_url = "002C99"; //--></script> <script type="text/javascript" src=""> </script>

You should feel free to challenge me, disagree with me, or tell me I'm completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever. That said, I will most likely only delete abusive, profane, rude, or annonymous comments, so keep it polite, please.


Cool .NET Articles

My .NET Tools

My Articles

My MSKB Articles

CodeSmith Rocks!

I've been working on building a really great web application using ASP.NET 2.0 over the past three months, and I needed a really great tool to make building the site easier. I tested a bunch of other tools (though I won't name them cause I'll get flamed), and I just wasn't satisfied. Not wanting to have to write any more code than I had to, I wanted to be able to design a platform that would allow me to easily change things as the requirements got more complex.

Enter CodeSmith. I'd heard a bunch of people rave about it, but I never really gave it a shot before. So I installed it, and as I started my trial, there was XHEO's Licensing component to taunt me. You see, I love XHEO's unreleased OR system. But unreleased = unsupported, and Paul's gung-ho on his anti-ILDASM technology, so I'm not holding my breath.

Anyways, I got it going, and was impressed. The IDE feels a little childish to me, and I was rather pissed that it didn't support VS2005 or .NET 2.0 language options, but oh well. The learning curve on the API was a tad steep too, but I picked it up pretty quickly. Soon, I had generated all of my SPROCS with ease.

But then my head started spinning when I thought of all the data access code I'd have to write. So I tried out some of the built-in templates, but I didn't like their access architecture. I'm a huge fan of the Provider Model, and I don't like data access code in the same class as the object properties. Yeah, it's nice to be able to call Object.Save(), but's it's just as nice to call ObjectManager.Save(object).

So I built myself a template to generate an ObjectManager. Then I wrote a template to generate all the Object Managers. Then I wrote a template to generate an object. Then I wrote a template to generate all the objects. Then I wrote a template to generate all the SPROCS, managers, and objects. And when I was done, I generated over 10,000 lines of code in just a few seconds. Not bad for a hard week's work.

In short, CodeSmith helped me do in a week what would have taken a team of 3 developers a month to accomplish. And I know that every single line of code is written to MY standards... something which is usually extremely tedious. I can't believe I waited this long to try it, and now I don't think I'll ever be able to code without it.

Maybe now I'll have time for all those little side projects... ;)


Mischa Kroon said:

You might want to have a look at

It's almost the same thing ... only it works better for me :)

You might want to have a look at what works best for you...
# December 8, 2005 4:47 AM

Jordan Terrell said:

Edit the .config files to use the following:

<requiredRuntime version="v2.0.50727" />

Make sure and remove all the "supportedRuntime" elements. Now you can use generics and anonymous methods in your CodeSmith templates. For example:

Action<int> writeValue = delegate(int inputValue)
{ %>
Your value is: <%= inputValue.ToString() %>
<% };



# December 8, 2005 10:04 AM

Jordan Terrell said:

Oh, I forgot to mention, CodeSmith 2.6 (the last freeware version) also works with .NET 2.0. Just edit the .config file to target .NET 2.0. Using anonymous methods in 2.6 allows you to create "sub-templates" inline. Either create your own delegate type or use Action<T> and you can pass the anonymous method input values, and it has access to the templates input properties.

# December 8, 2005 10:08 AM

Jeff Deville said:

Did you look at It's adapter model sounds like the provider model you described. All generated for you.
# December 8, 2005 10:10 AM

Chris Martin said:

Heh. 2002 called and wants it's headlines back.
# December 8, 2005 2:07 PM

Robert McLaws said:

Well, I removed those elements from the config file, but the IDE still doesn't properly highlight the syntax for new .NET methods. I can't blame them, because there are 30% more methods in 2.0, but it's still kinda annoying.

Mischa & Jeff- I said I wasn't going to mention names... I didn't like either one.
# December 8, 2005 2:26 PM

Jordan Terrell said:

I've never been impressed with the Intellisense or syntax highlighting in CodeSmith. I turned them off.

Robert - Were you able to get CodeSmith to compile to the .NET 2.0 framework?
# December 9, 2005 8:57 AM

Martin said:

Just a question. What is the advantages of CodeSmith 3 over MyGeneration? I installed it a while ago but the trial period expired before I had time to try it out...
# December 15, 2005 6:31 AM