Esempio n. 1
0
        public Expression <Func <T, bool> > GetFilterExpression <T>(IEnumerable <string> values) where T : SearchResultItem
        {
            DateTime startDate = DateTime.MinValue;
            DateTime endDate   = DateTime.MinValue;

            DateTime.TryParse(values.First(), out startDate);
            DateTime.TryParse(values.Last(), out endDate);

            // lets make sure items are within the day.
            if (endDate > DateTime.MinValue)
            {
                endDate = endDate.AddHours(23);
                endDate = endDate.AddMinutes(59);
                endDate = endDate.AddSeconds(59);
            }

            ParameterExpression expression = Expression.Parameter(typeof(T), "item");
            ConditionContext    context    = new ConditionContext(expression);

            var greaterThan = new Func <Expression, Expression, Expression>(Expression.GreaterThanOrEqual);
            var lessThan    = new Func <Expression, Expression, Expression>(Expression.LessThanOrEqual);

            var dateRangeExpression = Expression.Lambda <Func <T, bool> >(greaterThan(Expression.Property(context.ParameterExpression, typeof(T), SearchResultItemUtil.GetPropertyName <T>(InnerItem.Field_Name)), Expression.Constant(startDate)), new[] { expression });

            if (endDate > DateTime.MinValue)
            {
                dateRangeExpression = dateRangeExpression.And(Expression.Lambda <Func <T, bool> >(lessThan(Expression.Property(context.ParameterExpression, typeof(T), SearchResultItemUtil.GetPropertyName <T>(InnerItem.Field_Name)), Expression.Constant(endDate)), new[] { expression }));
            }

            return(dateRangeExpression);
        }
Esempio n. 2
0
        public Expression <Func <T, bool> > GetFilterExpression <T>(IEnumerable <string> values) where T : SearchResultItem
        {
            int year = ValidateInput(values.FirstOrDefault());

            // abort if input is no good
            if (year == 0)
            {
                return(null);
            }

            DateTime startTime = new DateTime(year, 1, 1);
            DateTime endTime   = new DateTime(year, 12, 31);

            ParameterExpression expression = Expression.Parameter(typeof(T), "item");
            ConditionContext    context    = new ConditionContext(expression);

            var greaterThan = new Func <Expression, Expression, Expression>(Expression.GreaterThanOrEqual);
            var lessThan    = new Func <Expression, Expression, Expression>(Expression.LessThanOrEqual);

            var dateRangeExpression = Expression.Lambda <Func <T, bool> >(greaterThan(Expression.Property(context.ParameterExpression, typeof(T), SearchResultItemUtil.GetPropertyName <T>(InnerItem.Field_Name)), Expression.Constant(startTime)), new[] { expression });

            dateRangeExpression = Expression.Lambda <Func <T, bool> >(lessThan(Expression.Property(context.ParameterExpression, typeof(T), SearchResultItemUtil.GetPropertyName <T>(InnerItem.Field_Name)), Expression.Constant(endTime)), new[] { expression });

            return(dateRangeExpression);
        }
 protected override Expression GetTypedFieldValueExpression(ConditionContext p_Context)
 {
     return(Expression.Property(p_Context.ParameterExpression, typeof(SearchResultItem), SearchResultItemUtil.GetPropertyName <SearchResultItem>(FieldName)));
 }
        public Expression <Func <T, bool> > GetFilterExpression <T>(IEnumerable <string> values) where T : SearchResultItem
        {
            bool comparison = false;

            bool.TryParse(values.FirstOrDefault(), out comparison);

            if ((!InnerItem.Apply_When_True && comparison) || (!InnerItem.Apply_When_False && !comparison))
            {
                return(null);
            }

            ParameterExpression expression = Expression.Parameter(typeof(T), "item");
            ConditionContext    context    = new ConditionContext(expression);

            var equals = new Func <Expression, Expression, Expression>(Expression.Equal);

            return(Expression.Lambda <Func <T, bool> >((Expression)equals(Expression.Property(context.ParameterExpression, typeof(T), SearchResultItemUtil.GetPropertyName <T>(InnerItem.Field_Name)), Expression.Constant(comparison)), new[] { expression }));
        }