更新时间:2023-11-07 23:15:46
要检查的第一件事-您是否已打开合同检查功能?如果没有,您的任何合同都不会做任何事情。那也将解释R#警告。在构建属性的代码合同下查看,并在运行时检查下查看其内容。
First thing to check - have you actually got contract checking turned on? If not, none of your contracts will do anything. That would explain the R# warning, too. Look under "Code Contracts" in the build properties, and see what it says under "Runtime Checking".
根据注释,确保您有 CONTRACTS_FULL
定义为编译符号-似乎是R#所需要的。
As per comments, ensure you have CONTRACTS_FULL
defined as a compilation symbol - that appears to be what R# requires.
第二点:您有公共可变字段,该字段是表示有人在任何时候都会侵犯您的不变式
Second point: you've got public mutable fields, which means your invariant can be violated at any moment by someone writing
polygon.VertexCount = 0;
请不要使用公共字段,尤其是不可写的字段。 :)
Please don't use public fields, particularly not writable ones. :)