Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code Contracts in Mono

The following code:

Contract.Requires<ArgumentException>(command != null, Resources.Messages.CommandNotSpecified);

calls

Contract.AssertMustUseRewriter (ContractFailureKind kind, System.String message)

which seems to be caused by not configuring Code Contracts to use runtime contract checking, if you were using Visual Studio.

the article @ http://devjourney.com/blog/code-contracts-part-2-preconditions/ implies that the code produced without runtime checking configured is:

public static void Requires<TException>(bool condition)
where TException: Exception
{
    AssertMustUseRewriter(ContractFailureKind.Precondition, "Requires<TException>");
}

Does anybody know what to do in MonoDevelop so that the contract works as expected?

The exact exception I'm getting is:

2012-11-13 23:33:24.815 StickX[339:c07] mvx: Diagnostic:  34.46 Exception masked NotImplementedException: The requested feature is not implemented.
      at System.Environment.FailFast (System.String message) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Environment.cs:821 
  at System.Diagnostics.Contracts.Contract.AssertMustUseRewriter (ContractFailureKind kind, System.String message) [0x00011] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Diagnostics.Contracts/Contract.cs:83 
  at System.Diagnostics.Contracts.Contract.Requires[ArgumentException] (Boolean condition, System.String userMessage) [0x00000] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Diagnostics.Contracts/Contract.cs:271 
like image 494
Martin Stafford Avatar asked Nov 13 '12 20:11

Martin Stafford


2 Answers

It's not implemented, so the only thing to make this work would be for you to write the implementation. Mono is an open source project, always happy to take new contributions.

like image 195
skolima Avatar answered Oct 16 '22 05:10

skolima


For your information the Microsoft CodeContracts are now OpenSource:

https://github.com/CodeContractsDotNet/CodeContracts

like image 35
FrancescoLogozzo Avatar answered Oct 16 '22 07:10

FrancescoLogozzo