You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Custom contract validators (methods marked with ContractArgumentValidator) should not contains any other calls of the Contract class except the call to the Contract.EndContractBlock:
[ContractArgumentValidator]publicvoidGuard(){// error CC1054: Contract argument validator 'InstanceValidator.Guard' cannot contain// ordinary contracts. Only if-then-throw or validator calls are allowed.if(!_condition)thrownewArgumentException();Contract.Ensures(false);Contract.EndContractBlock();}
Actually as part of this issue all other rules of the custom validators should be considered.
The text was updated successfully, but these errors were encountered:
Please consider the following scenario (tested and working):
You have an external library with some utility methods that perform standard argument validations (if/then/throw), but preceding that with standard Contract.Require calls to document the preconditions for the static checker (the static checker doesn't work very well with if/then/throw checks).
You want to compile this library emitting only the xxx.Contracts.dll file, to use alongside the aforementioned utility assembly. Doing so the Contract.Require calls do nothing in the released bits, but augment the CC reference library, used by the static checker.
You reference this assembly in a project that uses CC in Custom mode and with static checker enabled
Now the static checker will work as expected, thanks to the Contracts reference assembly augmented with standard Contract.Require calls. Otherwise you'll get weird warnings by the tool.
IMHO this enhancement should be removed or I should be able to selectively disable it..
Thanx
Custom contract validators (methods marked with
ContractArgumentValidator
) should not contains any other calls of theContract
class except the call to theContract.EndContractBlock
:Actually as part of this issue all other rules of the custom validators should be considered.
The text was updated successfully, but these errors were encountered: