I am just getting started with Code Contracts, and need a little help in correcting an error:
Given this code:
class MyClass
{
private bool _isUsed = false;
public void SomeMethod()
{
Contract.Requires(!_isUsed);
}
}
I get the following error:
error CC1038: Member 'MyClass._isUsed' has less visibility than the enclosing method 'MyClass.SomeMethod'
which seems to makes alot of the standard checks unavailable. What am I missing in this example?
It has already been explained that either _isUsed
has visibility issues (caller does not have control) which is rightly enforced by requires.
However, depending on what you are trying to accomplish with the Contract, Contract.Assert
may meet your needs.
public void SomeMethod()
{
Contract.Assert(!_isUsed);
}
would be valid while the Requires was not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With