我计划在第 3 方课程(Kentico)上使用一些 LINQ,但似乎无法这样做,我不知道为什么。我的代码本质上是:
using System;
using System.Collections.Generic;
using System.Linq;
// some additional namespaces
namespace test
{
public partial class ProductFilter : CMSAbstractBaseFilterControl
{
protected IEnumerable<String> GetCategories(String parentName)
{
CategoryInfo info = CategoryInfoProvider.GetCategoryInfo(parentName, CMSContext.CurrentSite.SiteName);
var children = CategoryInfoProvider.GetChildCategories(info.CategoryID, null, null, -1, null, CMSContext.CurrentSite.SiteID);
children.ToArray();
}
}
此时我得到错误
错误 5“CMS.SettingsProvider.InfoDataSet”不包含“ToArray”的定义,并且找不到接受“CMS.SettingsProvider.InfoDataSet”类型的第一个参数的扩展方法“ToArray”(您是否缺少 using 指令或装配参考?)
CategoryInfoProvider.GetChildCategories 定义为:
public static InfoDataSet<CategoryInfo> GetChildCategories(int categoryId, string where, string orderBy, int topN, string columns, int siteId);
InfoDataSet 定义为:
public class InfoDataSet<InfoType> : ObjectDataSet<BaseInfo>, IEnumerable<InfoType>, IInfoDataSet, IEnumerable where InfoType : CMS.SettingsProvider.BaseInfo, new()
{
public InfoDataSet();
public InfoDataSet(DataSet sourceData);
public InfoObjectCollection<InfoType> Items { get; protected set; }
protected InfoType Object { get; set; }
public InfoDataSet<InfoType> Clone();
public IEnumerator<InfoType> GetEnumerator();
public InfoType GetNewObject(DataRow dr);
protected override ObjectCollection<BaseInfo> NewCollection();
}
看起来接口已正确实现,我已经为 LINQ 包含了命名空间,并且我可以进行如下调用List<int> i; i.ToArray();
:我错过了哪一块拼图?