单声道代码合同

问题描述 投票:5回答:2

以下代码:

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

电话

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

如果您使用的是Visual Studio,这似乎是由于未将代码约定配置为使用运行时协定检查而导致的。

文章@ http://devjourney.com/blog/code-contracts-part-2-preconditions/暗示在没有配置运行时检查的情况下生成的代码是:

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

有没有人知道在MonoDevelop中做什么,以便合同按预期工作?

我得到的确切例外是:

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 
.net mono monodevelop code-contracts
2个回答
3
投票

It's not implemented,所以做这项工作的唯一方法就是编写实现。 Mono是一个开源项目,总是很乐意接受新的贡献。


2
投票

为了您的信息,Microsoft Code Contracts现在是开源的:

https://github.com/CodeContractsDotNet/CodeContracts

© www.soinside.com 2019 - 2024. All rights reserved.