Fluent Argument Validation

Roger Alsing has written some neat code for argument validation using fluent C# extension methods. Read the "How to validate a method’s arguments?" blog entry. Here's a sample taken from that blog entry.

public static void MyMethod(string someArg,int someOtherArg)
{
   someArg.RequireArgument("someArg")
          .NotNull()
          .ShorterThan(10)
          .StartsWith("Roger");

   someOtherArg.RequireArgument("someOtherArg")
               .InRange(10,100)
               .NotEqual(33)
               .NotEqual(51)
    //do stuff
}

He's also put together some of his other code into a mini-framework for download. The async fork is another another class worth taking a look at for a nice clean way to run asyncronous tasks.

Published Thursday, May 29, 2008 10:18 AM by colin
Filed under:

Comments

# re: Fluent Argument Validation

This is cool, did not know you can do it like this. Tx

Thursday, May 29, 2008 2:11 PM by hannes