if (string.IsNullOrEmpty(SearchString)) return null;
var left = Expression.Parameter(typeof(T), \"m\");
Expression expression = Expression.Constant(false);
T obj = default(T);
var type = typeof(T);
obj = (T)Activator.CreateInstance(type);
var propertyInfos = type.GetProperties();
foreach (var propertyInfo in propertyInfos)
{
if (propertyInfo.Name.ToLower() == \"id\" || propertyInfo.PropertyType == typeof(DateTime)) continue;
Expression tostring = Expression.Call
(
Expression.Property(left, typeof(T).GetProperty(propertyInfo.Name).Name),
typeof(object).GetMethod(\"ToString\", new Type[] { })
);
Expression right = Expression.Call
(
tostring,
typeof(string).GetMethod(\"Contains\", new Type[] { typeof(string) }),
Expression.Constant(SearchString)
);
expression = Expression.Or(right, expression);
}
filter = Expression.Lambda<Func<T, bool>>(expression, new[] { left });
return filter;
}
本文地址:https://www.stayed.cn/item/14464
转载请注明出处。
本站部分内容来源于网络,如侵犯到您的权益,请 联系我