I'm doing a simple test of Code Contracts. The following code is in a winform. This passes (of course):
private void Test(Form form)
{
Contract.Requires(!string.IsNullOrEmpty(form.Name));
MessageBox.Show(form.Name);
}
protected override void OnLoad(EventArgs e)
{
if (!string.IsNullOrEmpty(Name))
Test(this);
base.OnLoad(e);
}
However, I add just a very simple level of indirection, it says "requires unproven":
private bool Valid(string str)
{
return !string.IsNullOrEmpty(str);
}
protected override void OnLoad(EventArgs e)
{
if (Valid(Name))
Test(this);
base.OnLoad(e);
}
This seems like it would be trivial to prove. Why isn't it working?