c#反射表达式树模糊搜索示例
复制代码 代码如下: public static Expression<Func<T,bool>> GetSearchExpression<T>(string SearchString) { Expression<Func<T,bool>> filter = null; if (string.IsNullOrEmpty(SearchString)) return null; Expression expression = Expression.Constant(false); foreach (var propertyInfo in propertyInfos) if (propertyInfo.Name.ToLower() == "id" || propertyInfo.PropertyType == typeof(DateTime)) continue; typeof(object).GetMethod("ToString",new Type[] { }) ); ( tostring, typeof(string).GetMethod("Contains",new Type[] { typeof(string) }), Expression.Constant(SearchString) ); filter = Expression.Lambda<Func<T,bool>>(expression,new[] { left }); return filter; } 您可能感兴趣的文章:
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |