使用 ToList转换 Sitecore Item[] 时出现问题
使用 Sitecore 和 Linq 扩展。
我正在尝试使用以下代码将项目数组转换为列表:
Item variationsFolder = masterDB.SelectSingleItem(VariationsFolderID.ToString());
List<Item> variationList = variationsFolder.GetChildren().ToList<Item>();
但是,每当我尝试构建时,我都会收到此错误
'Sitecore.Collections.ChildList' does not contain a definition for 'ToList' and the best extension method overload 'System.Linq.Enumerable.ToList<TSource>(System.Collections.Generic.IEnumerable<TSource>)' has some invalid arguments
:我有以下用途:
using System.Linq;
using System.Xml.Linq;
正在引用:
System.Core
我刚刚从另一个代码复制了此代码位置,所以它应该工作正常,只能认为有一些简单的东西(比如参考资料或我缺少的东西)。
Working with Sitecore and Linq extensions.
I am trying to convert to from an item array to the list using the following piece of code:
Item variationsFolder = masterDB.SelectSingleItem(VariationsFolderID.ToString());
List<Item> variationList = variationsFolder.GetChildren().ToList<Item>();
However I keep getting this error whenever I try to build:
'Sitecore.Collections.ChildList' does not contain a definition for 'ToList' and the best extension method overload 'System.Linq.Enumerable.ToList<TSource>(System.Collections.Generic.IEnumerable<TSource>)' has some invalid arguments
I have the following usings:
using System.Linq;
using System.Xml.Linq;
Am referencing:
System.Core
I've just copied this code from another location, so it should work fine, can only think that there is something simple (like a reference or something that I am missing).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我没有任何使用 SiteCore 的经验,但是
ChildList
是否实现IEnumerable
而不是IEnumerable
?如果是这样,请尝试以下操作:
基本上
Cast
通过转换每个元素将IEnumerable
转换为IEnumerable
。I don't have any experience with SiteCore, but does
ChildList
implementIEnumerable
rather thanIEnumerable<T>
perhaps?If so, try this:
Basically
Cast<T>
converts anIEnumerable
toIEnumerable<T>
by casting each element.