How to build an IEnumerable<int>.Contains() Expression?

风格不统一 提交于 2019-12-01 12:12:31

There are two problems in your code:

  1. Your parameters are backwards. The first parameter has to be the collection, the second the item you're searching for.
  2. Your type argument is IEnumerable<int>, when it should be just int.

So, the fixed code is:

var callExpression = Expression.Call(
    typeof(Enumerable), "Contains", new[] { typeof(int) }, me, ce);

But it seems all the parts of your expression are not actually dynamic, so maybe something like that following would work too:

Expression<Func<Segment, bool>> expression =
    s => s.RouteIds.Contains(int.Parse(this.ddlRouteNames.SelectedValue));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!