Assume the following code:
public class CC3
{
private string _field;
private bool _someFlag;
public string Property
{
get { return _field; }
}
public bool SomeFlag
{
get { return _someFlag; }
}
public void SetField()
{
_field = " foo ";
_someFlag = true;
}
public string Method()
{
Contract.Requires(SomeFlag);
return Property.Trim();
}
}
The static checker of Code Contracts complains about the return
statement of Method
:
Possibly calling a method on a null reference 'this.Property'
What do I have to do to enable the static checker to prove that Property
can never be null
if SomeFlag
is true
?