System.Xml.XmlResolver缺少合同? [英] System.Xml.XmlResolver missing contract?

查看:57
本文介绍了System.Xml.XmlResolver缺少合同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

警告  2  CodeContracts:方法'MySchemaProvider.GetEntity(System.Uri,System.String,System.Type)'覆盖'System.Xml.XmlResolver.GetEntity(System.Uri,System.String,System .Type)',因此无法添加Requires。 

Warning 2 CodeContracts: Method 'MySchemaProvider.GetEntity(System.Uri,System.String,System.Type)' overrides 'System.Xml.XmlResolver.GetEntity(System.Uri,System.String,System.Type)', thus cannot add Requires. 

这是System.Xml.XmlResolver缺少的合同吗?

Is this a missing contract from System.Xml.XmlResolver?

推荐答案

嗨罗宾,

不,你根本无法为方法覆盖或接口实现添加新的前置条件。 但是,您可以添加新的后置条件。

No, you simply cannot add new preconditions to method overrides or interface implementations.  You can, however, add new post-conditions.

创建对象时,可以将其转换为基本类型。 一旦被抛弃,可以直接调用虚拟方法,它将执行覆盖;但是,只有对基本类型的引用的任何调用者只能知道关于虚方法上指定的合同的
。 你加强的先决条件将是未知的。 如果允许,您将能够添加一些调用者无法满足的前提条件。

When an object is created it can be cast down to the base type.  Once cast down, a virtual method can be invoked directly and it will execute the override instead; however, any caller that only has a reference to the base type can only know about the contracts specified on the virtual method.  Your strengthened preconditions will be unknown.  If allowed, you'd be able to add preconditions that some callers cannot satisfy.

接口实现存在类似的问题,因此适用相同的规则;也就是说,你不能强化先决条件,但你可以加强后置条件。

A similar problem exists with interface implementations, thus the same rule applies; i.e., you cannot strengthen preconditions but you can strengthen post-conditions.

参见:

方法覆盖无法添加前置条件

http:/ /social.msdn.microsoft.com/Forums/en-US/codecontracts/thread/21741df1-a0eb-41cc-9065-fb6c8f503fa3

接口实现无法添加先决条件 - 为什么?

http://social.msdn.microsoft.com/Forums/en-US/codecontracts/thread/95578​​f9a-9575-4674-8217-0236283b1004/

Liskov替换原则(行为子类型)

http:// en。 wikipedia.org/wiki/Liskov_substitution_principle

- 戴夫


这篇关于System.Xml.XmlResolver缺少合同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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