Since I am currently experimenting with both the dsl-toolkit and PostSharp (which is a .net postcompiler) I thought of the following:
This 'language' allows you to draw a diagram defining your exception policies and drop classes from your project in them (meaning that exceptions thrown in these classes should be handled according to that exception policy).
It currently looks like the following:
1) In the toolbox you can see a list of classes currently in your project (organized by namespace).
2) On the drawing surface you can see 2 Exception policies “DataAccessExceptionPolicy” and “BusinessLogicExceptionPolicy”, they contain the classes “QouteDAL” and “GetQouteAction”
Drawing is fun, but what to do with this view?
Well, using PostSharp I’ve created a little program that:
1) Loads the dsl-file you created
2) Opens up the assembly the classes are part of
3) Modifies the assembly and inserts all the exceptionhandling code you never wrote a line of c# for!
The code for “GetQuoteAction” in this project looks like this:
public class GetQuoteAction
public Quote Execute(string qoute)
double value = QouteDAL.GetQouteFromDB(qoute);
return new Quote(value);
Though, after compiling (and having the program run as a post-build step), the actual IL in it the output-assembly would look like the following in C#:
In case you where wondering:
yes – I’ll put the solution on my weblog as soon as I got my mind around howto deploy it
no – I haven’t tested it on complex scenario’s. The mangling of assembly instructions is done by postsharp, and I know Gael is eager on receiving feedback.
yes – Writing dsl’s is hard, but after writing a couple of diagram’s you sort-of get the hang of it
no – Loading classes from your project into your dsl’s toolbox isn’t a smart thing to do, the toolbox items are loaded when visual studio is started – which means you will have to restart VS after adding classes to your project in order to add them to the model
yes – The days of writing exception management code are over! :-)