'Design By Contract' in C#

Posted by IAmCodeMonkey on Stack Overflow See other posts from Stack Overflow or by IAmCodeMonkey
Published on 2008-11-04T03:50:30Z Indexed on 2010/05/17 6:50 UTC
Read the original article Hit count: 398

Filed under:
|

I wanted to try a little design by contract in my latest C# application and wanted to have syntax akin to:

public string Foo()
{
    set {
        Assert.IsNotNull(value);
        Assert.IsTrue(value.Contains("bar"));
        _foo = value;
    }
}

I know I can get static methods like this from a unit test framework, but I wanted to know if something like this was already built-in to the language or if there was already some kind of framework floating around. I can write my own Assert functions, just don't want to reinvent the wheel.

© Stack Overflow or respective owner

Related posts about c#

Related posts about design-by-contract