Setting up Code Contracts in Visual Studio 2010
So I was trying to run some simple code with Code Contracts (that I haven't used for some time)
static void Main(string[] args)
{
double res = sqrt(-5);
}
static double sqrt(int a)
{
Contra开发者_C百科ct.Requires(a >= 0, "a must be >= 0!");
return Math.Sqrt(a);
}
But it doesn't seem to do anything at all when I run it. From what I recall from some months ago, it should throw up an error about a
being less than 0.
I reinstalled the Academic version from the Code Contracts site just to be safe and this still doesn't seem to be working. What are the steps needed to put Code Contracts to work?
EDIT: Resharper is telling me on Contract.Requires(a >= 0);
that the method is being skipped, as it is either "conditional or a partial method without implementation".
Thanks
You should check this web page: link text
You should go to the project properties, Code Contracts tab and click the Runtime checkboxes.
精彩评论