日期:2014-05-20  浏览次数:20756 次

反射模糊搜索非stirng类型问题
我想实现反射模糊搜索

   foreach (PropertyInfo propertyInfo in propertyInfos)
            {
                if (propertyInfo.Name == "id")
                    continue;

                Expression right = Expression.Call
                      (
                          Expression.Property(left, typeof(T).GetProperty(propertyInfo.Name).Name),
                         typeof(string).GetMethod("Contains", new Type[] { typeof(string) }),
                        Expression.Constant(SearchString)
                      );
                expression = Expression.Or(right, expression);
            }


 Expression.Property(left, typeof(T).GetProperty(propertyInfo.Name).Name)这里遇到不是stirng的字段类型用不了Contains的错误提示,请高手指点一下

------解决方案--------------------
你都调用了string的Contains

不会试试看

typeof(object).GetMethod("ToString"