Пример #1
0
        private static Expression <Func <T, bool> > CreateDateTimeComparerLambda <T>(Expression expression, ParameterExpression parameter, string keyword)
        {
            var indexOfEmptySpace = Expression.Call(expression, InternalExpressionExtensions.GetIndexOfMethod(), Expression.Constant(" "));
            var dateExpression    = Expression.Call(expression, InternalExpressionExtensions.GetSubstringWithStartAndEndMethod(), Expression.Constant(0), indexOfEmptySpace);
            var timeExpression    = Expression.Call(expression, InternalExpressionExtensions.GetSubstringWithStartMethod(), Expression.Add(indexOfEmptySpace, Expression.Constant(1)));

            var date = keyword;
            var time = keyword;

            if (keyword.Contains(' ') == true)
            {
                var dateAndTime = keyword.Split(new char[] { ' ' });

                var dateComparerExpression = GetDateComparerExpression <T>(dateExpression, parameter, dateAndTime[0]);
                var timeComparerExpression = GetTimeComparerExpression <T>(timeExpression, parameter, dateAndTime[1], InternalExpressionExtensions.GetStartsWithMethod());

                //o => o.ComparerMethod((property ?? "").Substring(0, property.IndexOf(' ')).ToLower().Contains(date))
                //  .And(o.ComparerMethod((property ?? "").Substring(property.IndexOf(' ')).ToLower().StartsWith(time)))
                return(dateComparerExpression.And(timeComparerExpression));
            }
            else
            {
                var dateComparerExpression = GetDateComparerExpression <T>(dateExpression, parameter, date);
                var timeComparerExpression = GetTimeComparerExpression <T>(timeExpression, parameter, time, InternalExpressionExtensions.GetContainsMethod());

                //o => o.ComparerMethod((property ?? "").Substring(0, property.IndexOf(' ')).ToLower().Contains(date))
                //  .Or(o.ComparerMethod((property ?? "").Substring(property.IndexOf(' ')).ToLower().Contains(time)))
                return(dateComparerExpression.Or(timeComparerExpression));
            }
        }
Пример #2
0
        private static Expression <Func <T, bool> > GetDateComparerExpression <T>(Expression dateExpression, ParameterExpression parameter, string date)
        {
            var compareDateExpression = Expression.Call(dateExpression, InternalExpressionExtensions.GetContainsMethod(), Expression.Constant(date, typeof(string)));

            return(Expression.Lambda <Func <T, bool> >(compareDateExpression, parameter));
        }