我正在尝试构建一个谓词构建器,它返回一个谓词,该谓词检查一个整数列表是否包含另一个整数列表。到目前为止我有这个
public static Expression<Func<T, bool>> DynamicIntContains<T, TProperty>(string property, IEnumerable<TProperty> items)
{
var pe = Expression.Parameter(typeof(T));
var me = Expression.Property(pe, property);
var ce = Expression.Constant(items);
var call = Expression.Call(typeof(List<int>), typeof(List<int>).GetMethod("Contains").Name, new[] { typeof(int) }, ce, me);
return Expression.Lambda<Func<T, bool>>(call, pe);
}
T 是包含 ID 列表作为其属性之一的搜索对象。TProperty 是整数列表,属性是属性列表的名称。我得到的错误是
Additional information: No method 'Contains' exists on type 'System.Collections.Generic.List`1[System.Int32]'.
这是因为我是从静态方法调用它吗?还是我试图错误地访问 typeof(List) 上的方法?谢谢。