Roger Alsing Weblog

Argument validation framework released

with 3 comments

Download:
http://www.puzzleframework.com/Roger/alsingcore.zip

I’ve finally got my thumb out and cleaned up and made a mini framework of the fluent argument validation concept I blogged about in my last post: http://rogeralsing.com/2008/05/10/followup-how-to-validate-a-methods-arguments/

The framework contains a little bit of everything.

Fluent Argument Validation Specification.
An extensible argument validation system based on a fluent extension method API.
(Maybe I should work at marketing ;-) )

Async fork.
A fluent API for performing async operations.

Text parser.
A Deterministic Finite-State Automata based parser.
It is the same parser that we used in NPath for NPersist but with a cleaned up API.

Flextensions.
A handful of useful extension methods to increase expressiveness.
Loggers, casting, formatting etc.

Generic Math.
A generic numeric type that supports math operations.

 

Examples:

Validation pre conditions:

static string ValidationFunc(int a,string b,DateTime c)
{
  //pre conditions:
  a.Require("a")
   .IsGreaterThan(10);

  b.Require("b")
   .NotNull()
   .NotEmpty()
   .LongerThan(2)
   .StartsWith("Ro");

  c.Require("c")
   .IsInRange(new DateTime(2000, 01, 01),
   new DateTime(2010, 01, 01));

Validation post conditions:

string res = "Foo";
//post condition:
return res.Require("res")
          .NotNull()
          .LongerThan(2)
          .ShorterThan(100);

Async fork:

static int ForkIt()
{
   int a = 0;
   int b = 0;

   //begin async fork
   Fork.Begin()
       .Call(() => a = SomeSlowCall())
       .Call(() => b = SomeOtherSlowCall())
       .End();
   //async fork done
   return a + b;
}

Flextensions:

//fluent casts, no need to wrap in ((int)var).
someVar.Cast<Foo>().Bar();
someVar.As<Boo>().Yoo();

//formatting and output;
myVar.FormatAs("myVar is: {0}").Output();

"Hello {0} {1}".FormatWith(firstName,LastName).Output();

"ROGER ALSING".ToProperCase().Output();

//string matching
bool match = myString.Like("Roger%");
bool match = myString.Match(regexPattern);

 More examples can be found in the demo project and in the unit tests in the same zip as the framework. 

Enjoy.
//Roger

Download:
http://www.puzzleframework.com/Roger/alsingcore.zip

Written by Roger Alsing

May 28, 2008 at 9:33 pm

Posted in .NET, Architecture, C#

3 Responses to 'Argument validation framework released'

Subscribe to comments with RSS or TrackBack to 'Argument validation framework released'.

  1. Hi Roger

    Nice work. I actually began messing about making my own framework based on your idea, never got anything finished though.

    How do the “Fork Async” feature work? Do it call the different validations on their own thread and wait till all of them finishes?

    Egil

    28 May 08 at 10:09 pm

  2. Hi Roger,

    Like Egil, I started building my own framework based on your idea. Hopefully, I’ll be able to publish it on CodePlex in a couple of days. You can read more about it on my blog.

    Steven

    9 Jul 08 at 6:32 pm

  3. [...] até empacotou tudo em um [...]

Leave a Reply