本文介绍了来自重写者的不必要的警告,它实际上不应该注入合同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

假设我有一个继承自Collection< T>的类。并实现额外的接口IList< TOther>在这堂课上。 IList< TOther> .RemoveAt的实现继承自Collection< T>。和重写者抱怨它,
建议添加一个包装器方法,以便它可以将前置和后置条件注入到这个包装器中。

Suppose I have a class inherited from Collection<T> and implementing additional interface IList<TOther> in this class. The implementation of IList<TOther>.RemoveAt is inherited from Collection<T> and rewriter complains about it and suggests to add a wrapper method so that it could inject pre and postconditions into this wrapper.

1。如果整个类被标记为[ContractOption(" runtime"," checking",false)](我不希望在此类中进行运行时检查),则不应出现此警告

1. This warning shouldn't appear if the whole class is marked as [ContractOption("runtime", "checking", false)] (I don't want runtime checking in this class)

2。如果只需要在方法中注入后置条件但项目的运行时检查级别设置为"仅限前置条件"

2. This warning shouldn't appear if only postconditions need to be injected in a method but the runtime checking level for the project is set to 'Preconditions only'

,则不应出现此警告。更一般地说,此警告应显示为 仅当特定方法实际需要注入时。否则,我们被迫无缘无故地添加包装器方法(即使从运行时检查/重写中排除了整个类)。

More generally, this warning should appear only when the injection is actually needed for a particular method. Otherwise, we are forced to add wrapper methods for no reason (even if a whole class is exluded from runtime checking/rewriting).

推荐答案

[ContractOption(" contract"," inheritance",false)]

[ContractOption("contract", "inheritance", false)]

[ContractOption("runtime","check",false)]

[ContractOption("runtime", "checking", false)]

[SuppressMessage("Microsoft.Contracts","CC1079")]

[SuppressMessage("Microsoft.Contracts", "CC1079")]


这篇关于来自重写者的不必要的警告,它实际上不应该注入合同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-26 23:13