我有另一个简单的(我认为)难倒了我。我已经在我的一个控件中编写了一个方法,该方法在给定文件名的情况下获取 CMS 中文件的最新版本(即,无论文件位于哪个文件夹)。我发现它非常有用,我想我应该把它放在我的 CMSToolbox 类中,但是当我这样做时,我不能再使用 CMS 提供的 FileManager 类的 Where()
方法(它返回一个列表)。
这是我的类(class)的一个简化示例:
using System;
using System.Collections.Generic;
using CMS.CMS;
using CMS.Core;
using CMS.Web;
namespace CoA.CMS {
public class ToolBox
{
public CMS.CMS.File getLatestFileVersionByFilename(string filename, int GroupID)
{
IList<CMS.CMS.File> fileWithName = FileManager.GetGroupAll(false, GroupID).Where(file => currentFileVersionIsNamed(file, filename)).ToList<CMS.CMS.File>();
return getLatestFileFromListOfFiles(fileWithName);
}
protected bool currentFileVersionIsNamed(CMS.CMS.File file, string name)
{
}
protected CMS.CMS.File getLatestFileFromListOfFiles(CMS.CMS.File file)
{
}
}
}
当我在控件(实际上是 CMS 提供的扩展 Control
的类)上下文中执行完全相同的操作时,我可以访问 Where()
方法,但在我的 ToolBox 类中我没有。是什么赋予了?我认为 IList
将始终允许从您使用它的任何地方访问相同的方法。
我又错了,哈哈:)
编辑:Filemanager.GetGroupAll()
返回一个扩展 IList
的 CMSList
最佳答案
您需要为 System.Linq
使用指令. .Where()
是 IEnumerable<T>
上的扩展方法(IList<T>
实现)在 System.Linq 命名空间中定义。
关于C# 初学者 : Where has my IList. Where() 方法不见了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1760719/