【发布时间】:2019-02-17 15:19:11
【问题描述】:
我的表达学习真的很基础,我有如下函数谓词
Func<RecordViewModel, Func<ReportModel, bool>> exp = rec => x => x.Firstname == rec.Firstname &&
x.Surname == rec.Surname;
var func = exp(new RecordViewModel() { Firstname= "Peter", Surname = "Jones" });
以下是我的模型和视图模型,
public class ReportModel
{
public string Firstname { get; set; }
public string Surname { get; set; }
}
public class RecordViewModel
{
public string Firstname { get; set; }
public string Surname { get; set; }
}
我想让表达式序列化为 ((ReportModel.Firstname == "Peter") AndAlso (ReportModel.Surname == "Jones"))。
非常感谢任何帮助,
【问题讨论】:
-
我相信您正在尝试检查名字为“Peter”且姓氏为“John”的
ReportModel,然后将结果返回为RecordViewModel,对吗? -
不,ReportModel 是来自 UI 的参数,并且希望将过滤条件记录为字符串
-
所以返回应该是字符串而不是布尔值?
-
是的,一个字符串,例如 ((ReportModel.Firstname == "Peter") AndAlso (ReportModel.Surname == "Jones"))。类似stackoverflow.com/questions/15478711/…
-
我还是不明白。