Contract.Requires
is declared as
[ConditionalAttribute("CONTRACTS_FULL")] public static void Requires( bool condition ) [ConditionalAttribute("CONTRACTS_FULL")] public static void Requires( bool condition, string userMessage )
which means that if the CONTRACTS_FULL
symbol is not defined, any call to Requires
will be removed by the compiler completely. The check will not be performed at all.
If you do define the CONTRACTS_FULL
symbol, but you don't have Code Contracts installed at build time or do not use its rewriter, any call to Requires
will throw an exception regardless of whether the check passes, telling you that without the Code Contracts rewriter, it won't work.
Note: this is different from Contract.Requires<TException>
. The latter does not have the same ConditionalAttribute
, so will fail in any configuration unless the Code Contracts rewriter is used.