合同继承自ICollection CopyTo [英] Contract inherited from ICollection CopyTo

查看:92
本文介绍了合同继承自ICollection CopyTo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许VS 2010编辑器扩展显示错误,但这就是我在屏幕上看到的。

Maybe VS 2010 Editor Extensions shows something wrong, but that is what I see on the screen.

继承合同要求:

ICollection.CopyTo

需要 数组!= null
// '=='运算符可以重载,使用Object.ReferenceEquals

需要 array.Rank == 1
// ok

需要 index> = 0
// ok

需要 index< = array.Length + this.Count
// 错误,必须是array.Length - this.Count < /强>




ICollection< T> .CopyTo

需要 数组!= null //
'=='运算符可以重载,使用Object.ReferenceEquals


需要 arrayIndex> = 0
// ok

需要 arrayIndex + this.Count< array.Length
// 错误,如果arrayIndex + this.Count> int.MaxValue ,arrayIndex + this.Count将溢出

ICollection.CopyTo
requires array != null // '==' operator can be overloaded, use Object.ReferenceEquals
requires array.Rank == 1 // ok
requires index >= 0 // ok
requires index <= array.Length + this.Count // wrong, must be array.Length - this.Count

ICollection<T>.CopyTo
requires array != null // '==' operator can be overloaded, use Object.ReferenceEquals
requires arrayIndex >= 0 // ok
requires arrayIndex + this.Count < array.Length // wrong, arrayIndex+this.Count will overflow if arrayIndex+this.Count>int.MaxValue




推荐答案

感谢您的注意。

Thanks for noticing.

过载问题是一个红鲱鱼。我们的合同被编译并存储在被调用者的IL级别,因此不会出现超载。

The overload issue is a red-herring. Our contracts are compiled and stored at the IL level in the callee, so no overloading applies.

我在ICollection.CopyTo上修复了明显错误的合同。有趣的是之前没有注意到。我把它们做成了非溢出的类型:

I fixed the obviously wrong contract on ICollection.CopyTo. Funny this wasn't noticed before. I made them of the non-overflowing kind:

index< = array.Length - this.Count

index <= array.Length - this.Count

再次感谢。


这篇关于合同继承自ICollection CopyTo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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