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

<pre><code>public string Foo()
{
    set {
        Assert.IsNotNull(value);
        Assert.IsTrue(value.Contains("bar"));
        _foo = value;
    }
}
</code></pre>

<p>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.</p>

Aside from using an external library, you have a simple assert in System.Diagnostics:
```
```
using System.Diagnostics

Debug.Assert(value != null);
Debug.Assert(value == true);
```
```
Not very useful, I know.