Sharp and dynamic

While hacking some code generator app in c# I ran into some issues. Being a compiled language, extending some parts of the generator would require recompiling the app, so if I want to use it in my project that mean I’d have to drag the source code all around… I don’t like the idea. I strongly think that all dev tools should be quickly extendable. I think that’s the main reason more and more devs are turning on to python, ruby and other scripting language.
The problems is, I’m using c#, and I don’t want to mix languages like that for the simple purpose of using a code generator… That’s when something popped up in my head. I remember something, somewhere deep in the .NET System.CodeDom namespace that could dynamically compile c# code and run it in the actual assembly. Yeah! If I can do that I can run c# code as script!!!
Too bad Oleg Shilo thought about it before I did, here’s the result
I think this is opening a new world of possibility to the .net framework and .net dev tools. Imagine creating build script in c#, the only thing missing maybe is a couple of helper classes and methods…

Speaking of my code generator. You may ask why? Why another code generator, please! No! Not again! Let me explain…
All generator tools are based on the template to file pattern, or are optimized for this. Open a template, then parse it to a file, then use this file. I want to push this a step further, and I wont hide the fact that I’m porting some ruby’s generator concepts. So the patterns should be, send the generator some arguments and the the files are generated and parsed directly in your app directory structured. Simple, clean and mostly FAST. But not very portable since you app directory structure is not mine… That why all the generator logic is one class that inherits Generator and overrides a run methods. In the methods you do what you have to do:

public class TestGenerator : Generator
public override void Run(string[] args)
AddParameter("test", args[0]);

ProcessTemplate("Test.vm", @"Temp\SomeTest.txt");

For now I’m using NVelocity template engine. I think this could get any more simple. You can pass parameters to the template and then create the structure and parse your templates or any other dependencies to the folder you want.
The generator is launch with this : generate test Hello.

And what if I could create a dynamic scripting language with the System.CodeDom stuff! humm..


Leave a comment

Filed under Misc

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s