 <p>You should check out <a href="http://weblogs.asp.net/podwysocki/archive/2008/11/08/code-contracts-for-net-4-0-spec-comes-alive.aspx" rel="nofollow noreferrer"><strong>Code Contracts</strong></a>; they do pretty much exactly what you're asking. Example:</p> <pre><code>[Pure] public static double GetDistance(Point p1, Point p2) { CodeContract.RequiresAlways(p1 != null); CodeContract.RequiresAlways(p2 != null); // ... } </code></pre>