我最近开始玩 Linq(提示 groans),并试图编译以下内容。现在,whereclause 部分使用了 DynamicLinq,效果很好;它是编译器想要一个真正的类的 var 占位符变量;不幸的是,我正在使用我认为是匿名课程,并且不知道如何从这里获取它。有什么建议么?
var query;
if(whereclause != string.Empty)
{
query = Directory.GetFiles(LRSettings.Default.OperatingDirectory, LRSettings.Default.FileExtension,
SearchOption.AllDirectories).AsQueryable()
.Select(Filename => new { Filename, new FileInfo(Filename)
.LastWriteTime, new FileInfo(Filename).Extension, new FileInfo(Filename).Length })
.Where(whereclause);
}
else
{
query = Directory.GetFiles(LRSettings.Default.OperatingDirectory,
LRSettings.Default.FileExtension,
SearchOption.AllDirectories)
.AsQueryable()
.Select(Filename => new { Filename, new FileInfo(Filename).LastWriteTime, new FileInfo(Filename).Extension, new FileInfo(Filename).Length });
}