1
我有以下代码可以帮助我通过反射来构建lambda表达式。但是,当我尝试与Date
进行比较时,它会将我的值转换为完整DateTime
印章。我怎样才能建立我的谓词,所以它只会比较短日期?使用短日期构建动态lambda谓词
System.Reflection.PropertyInfo propInfo = typeof(T).GetProperty(property);
Type propertyType = propInfo.PropertyType;
if (Utilities.IsNullableType(propertyType))
{
propertyType = Nullable.GetUnderlyingType(propertyType);
}
ParameterExpression propAlias = Expression.Parameter(typeof(T), alias);
MemberExpression left = Expression.Property(propAlias, property);
ConstantExpression right = Expression.Constant(Convert.ChangeType(value, propertyType));
BinaryExpression comparer = BuildComparisonExpression(left, right, comparison);
return Expression.Lambda<Func<T, bool>>(comparer, propAlias);
我知道这是字符串转换为DateTime
的Convert.ChangeType
,但我得到的回复是item => item.DateToCheck == 1/1/2012 12:00:00AM
,当我想item => item.DateToCheck == 1/1/2012
。