Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any .NET Fluent Argument checking libraries out there? [closed]

while looking at Shrinkr's source code (we all review other project's source code to learn, right??? :) ) I noticed the following kewl code .. (abbreviated by me, below)

public virtual Foo Foo
{
    get;
    set 
    {
        Check.Argument.IsNotNull(value, "value"); 
        // then do something.
    }
}

Notice the fluent way they check for arguments? Nice :)

alt text
(source: cherrythian.com)

So .. checking the code, they have some custom class that does this...

public static class Check
{
    public static class Argument
    {
        public static void IsNotNull(object parameter, 
                                     string parameterName)
        { ... }

        public static void IsNotNullOrEmpty(string parameter, 
                                            string parameterName)
        { ... }

 .... etc ....
}

Are there any common frameworks out there?

gem install netFluentCheck ?

:)

like image 588
Pure.Krome Avatar asked Aug 03 '10 02:08

Pure.Krome


1 Answers

I ended up using CuttingEdge Conditions, found on Codeplex.

eg.

// Check all preconditions:
Condition.Requires(id, "id")
    .IsNotNull()          // throws ArgumentNullException on failure
    .IsInRange(1, 999)    // ArgumentOutOfRangeException on failure
    .IsNotEqualTo(128);   // throws ArgumentException on failure

nice :)

like image 100
Pure.Krome Avatar answered Sep 22 '22 21:09

Pure.Krome