Contract: Invariant is not verified by static verifier

I am experimenting with Code Contract, and I ran into one problem. I have a class:

public class SpecialPoint { public int X { get; set; } public int Y { get; set; } public SpecialPoint(int x, int y) { Contract.Requires<ArgumentException>(y > x); X = x; Y = y; } [ContractInvariantMethod] private void ClassContract() { Contract.Invariant(Y > X); } } 

and I will test against him:

 [TestFixture] class SpecialPointTests { [Test] public void SpecialPoint() { var p = new SpecialPoint(10, 20); pX = 30; } } 

I expected static checks to warn me about pX = 30; as this violates the invariant, but this only happens at runtime. I have the option of static analysis. My version is 1.7.11202.10.

+5
source share
1 answer

From the MSDN page in the Contract section. Invariant

During runtime verification , invariants are checked at the end of each public method.

+3
source

Source: https://habr.com/ru/post/1208800/


All Articles