var objectType = cmbObjectType.SelectedItem as Type;
var property = cmbProperty.SelectedItem as PropertyInfo;
var oper = cmbOperator.SelectedValue;
var item = Expression.Parameter(objectType);
var prop = Expression.Property(item, property);
BinaryExpression condition=null;
var filtered = tlproject.TlObjects.Where(obj => obj.GetType().Equals(objectType)).AsQueryable();
...
var lambda = Expression.Lambda<Func<TLObject, bool>>(condition, item);
var results = filtered.Where(lambda);
这不起作用,因为对象从TLObject继承,给出了像
这样的错误附加信息:ParameterExpression类型 'TLObjects.Pipe'不能用于类型的委托参数 'TLObjects.Base.TLObject'
我该如何解决这个问题? 的更新 这似乎有效
var item = Expression.Parameter(typeof(TLObject));
var itemConverted=Expression.Convert(item, objectType);
var prop = Expression.Property(itemConverted, property);