为什么不FxCop的规则" CA1002:不要暴露泛型列表"推荐使用的IList< T>? [英] Why doesn't fxcop rule "CA1002: Do not expose generic lists" recommend to use IList<T>?

查看:179
本文介绍了为什么不FxCop的规则" CA1002:不要暴露泛型列表"推荐使用的IList< T>?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的FxCop的规则CA1002:不要暴露泛型列表建议通过收藏< T> 在公共的API,而不是名单,其中,T>

FxCop's rule CA1002: "Do not expose generic lists" recommends passing Collection<T> across public API's rather than List<T>.

虽然它很好的学习收集和LT的; T&GT; 类,这似乎是不好的建议。我们仍然追平了API将具体的实现类。那岂不是更好地回报的IList&LT; T&GT; ?我们还是有灵活性,收藏&LT; T&GT; 将得到我们,我们也不得不在我们的处置轻松迁移到列表类找不到MS基类有用(举例来说,在System.Collections.Concurrent集合或其他集合的抽象并行的场景浮现在脑海中)。

While its nice to learn of the Collection<T> class, this seems like bad advice. We're still tying the API to a concrete implementation class. Wouldn't it be better to return IList<T>? We'd still have the flexibility that Collection<T> would get us, and we'd also have at our disposal easy migration to List classes that don't find the MS base classes useful (for examples, the collections in System.Collections.Concurrent or other collection abstractions in parallel scenarios come to mind).

我失去了一些东西在这里还是这只是坏的建议?

Am I missing something here or is this just bad advice?

推荐答案

http://blogs.msdn.com/b/$c$canalysis/archive/2006/04/27/585476.aspx

有一些很好的指针那里。

Some good pointers there.

这篇关于为什么不FxCop的规则&QUOT; CA1002:不要暴露泛型列表&QUOT;推荐使用的IList&LT; T&GT;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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