请教一个动态构建lamda表达式的问题
我想构建一个数组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;
}