C#: Code Contracts vs. normal parameter validation
In order to get rid of warnings you can use Contract.Assume
In order to get rid of warnings you can use Contract.Assume
I don’t think unit testing and contracts interfere with each other that much, and if anything contracts should help unit testing since it removes the need to add tedious repetitive tests for invalid arguments. Contracts specify the minimum you can expect from the function, whereas unit tests attempt to validate the actual behaviour for a … Read more
The last mature response to this was in 2009, and .NET 4 is out. I figure we’re due for an update: Code Contracts might well be mature enough for your Debug releases. I realise this is somewhat of an upgrade from “Harmless” to “Mostly Harmless”. The Code Contracts home page links to quite thorough documentation … Read more
Note: as of the current R# 8.0 EAP, this functionality is included. Here’s the solution for the current (i.e. .NET 4.0) version of Code Contracts: Inside …\ExternalAnnotations\mscorlib\Contracts.xml, add the following: <assembly name=”mscorlib”> <member name=”M:System.Diagnostics.Contracts.Contract.Assert(System.Boolean)”> <attribute ctor=”M:JetBrains.Annotations.AssertionMethodAttribute.#ctor”/> <parameter name=”condition”> <attribute ctor=”M:JetBrains.Annotations.AssertionConditionAttribute.#ctor(JetBrains.Annotations.AssertionConditionType)”> <argument>0</argument> </attribute> </parameter> </member> <member name=”M:System.Diagnostics.Contracts.Contract.Assert(System.Boolean, System.String)”> <attribute ctor=”M:JetBrains.Annotations.AssertionMethodAttribute.#ctor”/> <parameter name=”condition”> <attribute ctor=”M:JetBrains.Annotations.AssertionConditionAttribute.#ctor(JetBrains.Annotations.AssertionConditionType)”> <argument>0</argument> </attribute> … Read more