请教一个动态构建lamda表达式的问题

liveths liveths 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我想构建一个数组Contains方法判断是否包含的表达式。但是好像我的代码老是出错。。。。特来请教大神。
目标构建的表达式:
x => userIDS.Contains(x.NewBy)

string exMsg = string.Empty;
Expression<Func<Modelv_SA_WinOrder, bool>> exe = null;
string[] userIDS = new string[] { "1", "2" };

try
{
ParameterExpression paramEx = Expression.Parameter(typeof(Modelv_SA_WinOrder), "x");
Expression ex = Expression.Call(
Expression.Constant(userIDS),
typeof(string[]).GetMethod("Contains"),
Expression.Property(paramEx, typeof(Modelv_SA_WinOrder).GetProperty("NewBy"))
);
exe = Expression.Lambda<Func<Modelv_SA_WinOrder, bool>>(ex, new ParameterExpression[] { paramEx });

//GDMM

//newData = dALt_SA_WinOrder.GetDatas();

//userIDS = userDAL.GetOrganizationDataByUserCLTID("MC");
//userDAL.FilterDataByUserOrganization<Modelv_SA_WinOrder>(newData, "NewBy");
}
catch (Exception ex)
{
exMsg = ex.Message;
}
...全文

相关推荐

评论 1
收藏 已收藏
分享
返回顶部
liveths
.NET社区 62,274 成员 668,968 内容