合同类应该是一个抽象类 [英] Contract class should be an abstract class

查看:251
本文介绍了合同类应该是一个抽象类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码为我提供警告 Contract类'FooContracts'应该是一个抽象类。从我在线阅读的所有示例(例如 http://www.infoq.com/articles/code-contracts -csharp ),这应该工作(可能没有编译器警告)。

The following code gives me the warning Contract class 'FooContracts' should be an abstract class. From all the examples I've read online (e.g. http://www.infoq.com/articles/code-contracts-csharp), this should work (presumably without compiler warnings).

[ContractClass(typeof(FooContracts))]
public interface IFoo {
  void Bar(string foo);
}

[ContractClassFor(typeof(IFoo))]
internal sealed class FooContracts : IFoo {
  void IFoo.Bar(string foo) {
    Contract.Requires(foo != null);
  }
}

我在Visual Studio 2010中,项目属性的代码合同部分中的设置:

I'm in Visual Studio 2010, with the following settings in the Code Contracts section of the project's properties:


  • 执行运行时合同检查(设置为完全

  • 执行静态合同检查)

  • 签入背景

我也定义了 CONTRACTS_FULL 编译符号使ReSharper关闭。

I also defined the CONTRACTS_FULL compilation symbol to make ReSharper shut up.

我缺少一些东西使这个编译没有警告吗?

Am I missing something to make this compile without warnings?

推荐答案

代码合同手册的第2.8节明确声明它应该是一个抽象类:

Section 2.8 of the code contracts manual specifically states that it should be an abstract class:


工具期望合同类是抽象的并实现接口正在为。

The tools expect that the contract class is abstract and implements the interface it is providing contracts for.

这篇关于合同类应该是一个抽象类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆