tags:

views:

316

answers:

7

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?

+2  A: 

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.

48klocs
A: 

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.

Nader Shirazie
Looks nice. But I would require something that could be part of a class library. And from what I have seen this requires java. But good nonetheless
Dejan
Ah, sorry. Here: http://www.antlr2.org/doc/csharp-runtime.html
Nader Shirazie
A: 

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.

Scott Wisniewski
"neither C# nor VB offers any meta programming features". ah, but these aren't the only clr languages. check out boo or nemerle.
anthony
So, people who use SQL or XSLT are not writing "real software", and their code is "rarely effective" ?
Max Toro
The point you are missing is "in isolation". Most of the time those languages are embedded inside another language (Java, C#, VB, Ruby, etc). Usually they are embedded as strings that are processed by APIs. That's very far from ideal, however. Linq offers a much more effective development experience than "pure ADO.NET" does. The point is to prefer deep integration of a DSL with a host, rather than isolation. The problem isn't DSLs, it's isolated DSLs. Integrated = good, Isolated = bad
Scott Wisniewski
A: 

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.

anthony
A: 

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

Matt
A: 

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.

Gutzofter
A: 

You can try DSL Tools for Visual Studio.

Luis Filipe