任何.NET Fluent Argument检查那里的库?

Pur*_*ome 9 .net c# fluentvalidation fluentvalidation-2.0

在看Shrinkr的源代码时(我们都会查看其他项目的源代码来学习,对吧??? :))我注意到以下的kewl代码..(以下简称)

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

注意他们检查参数的流畅方式?好:)

alt text http://cherrythian.com/images/borat.jpg

所以..检查代码,他们有一些自定义类,这样做...

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 ....
}
Run Code Online (Sandbox Code Playgroud)

那里有没有共同的框架?

gem install netFluentCheck

:)

Pur*_*ome 6

我最终使用了Codeplex上的CuttingEdge条件.

例如.

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

好:)

  • CuttingEdge.Conditions是shizzle ;-) (3认同)