Question

For a little night project I would like to write a validation component that could be used in .NET application to do the usual and tedious validation of object, input parameters and post conditions.

My first idea was to dump all this validation setup logic into a XML configuation file and provide a liquid interface for the people that would like to have it in code.

Because I would like to deliver something that is actually usable I thought about providing a specialized DSL (domain specific language). The question is what tools should I use to do this?

I thought about parsing it by hand using regex. But personally I would like to have something more...usable.

So what would you suggest?

Was it helpful?

Solution

If you're looking specifically at a DSL, have a look at the ANTLR project. We've used it at my company quite successfully in the past.

OTHER TIPS

It sounds like you're talking about implementing one of .Net 4.0's features, code contracts.

So I guess my recommended tool would be VS.Net 2010.

The thing with DSl's is that they rarely are effective in isolation. To be useful for writing real software, you really need to be able to embed the DSL inside a host language. Compare, for example, the way Linq works vs just straight SQL. Another good example is XML literal feature in VB. Both let you write real code, in a general purpose PL and inter weave it with simpler declaritive DSL code.

The result is something much more powerful than stand alone SQL or a simple XML editor.

The downside to this, unfortunately, is that neither C# nor VB offers any meta programming features, so the only way to do that for mainstream .net devs is to build your own language. If this is something you are doing just for fun you might be able to modify the mono C# compiler to add the features you are interested on to the language. Another alternative might be to try ruby. It has a flexible syntax whic let's you get away with a lot of crazyness. Personaly, however, I would prefer the hacked C# approach.

Might want to check out Building Domain Specific Languages in Boo (Boo is a CLR language, concepts should carry over to C#). An example project is Simple State Machine.

Take a look at Oslo from Microsoft, not sure if it does what you want, but I know that you can build DSL parsers and specify grammars and have it generate class libraries that can parse data based on the grammar.

More details of the "M" language and how to use it are here

Why go so far? Start off using generics and a fluent interface. Start simple and work it through some production. If the friction is too high dealing with a fluent interface, then look at using a DSL.

You can try DSL Tools for Visual Studio.

You should look at Irony project at http://irony.codeplex.com/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top