相关疑难解决方法(0)

只能在IEnumerable上调用Cast和OfType

在我正在使用的库中,遇到调用IEnumerable之外的任何LINQ方法的问题。我有一个如下的类层次结构(命名有点奇怪,因为它被内部代码所混淆了)

Item : GeneralObject

ItemCollection : GenericCollection<ItemCollection, Item>

GenericCollection<TCollection, TItem> : GeneralObjectCollection, IEnumerable<TItem>
    where TCollection : GenericCollection<TCollection, TItem>
    where TItem : GeneralObject

GeneralObjectCollection : ICollection, IEnumerable<GeneralObject>
Run Code Online (Sandbox Code Playgroud)

可以看出,IEnumerable在ItemCollection的类层次结构中有两次,因此有两种GetEnumerator方法,一种提供a GeneralObject,一种提供a Item

当我查看VS2019中通过元数据提供的类定义时,实现的每个类IEnumerable<TItem>也显示为Implemented IEnumerable

With this setup, I am unable to call most LINQ methods like Select, Where, etc, on any ItemCollection instances, and can only do those on IEnumerable. It looks like it should clearly support methods on IEnumerable<T> as well, but …

c# linq ienumerable

0
推荐指数
1
解决办法
254
查看次数

标签 统计

c# ×1

ienumerable ×1

linq ×1