为什么不FxCop的规则" CA1002:不要暴露泛型列表"推荐使用的IList< T>?

为什么不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.