Esempio n. 1
0
        protected override RangeTuple <TVal> Parse(string filterArgument)
        {
            var range = new RangeTuple <TVal>();

            string[] values = filterArgument.Split('|');
            if (values.Length == 0)
            {
                return(range);
            }
            if (!string.IsNullOrEmpty(values[0]))
            {
                range.From    = ValueConverter.Convert <TVal>(values[0]);
                range.HasFrom = true;
            }
            if (values.Length > 1)
            {
                if (!string.IsNullOrEmpty(values[1]))
                {
                    range.To    = ValueConverter.Convert <TVal>(values[1]);
                    range.HasTo = true;
                }
            }
            return(range);
        }
Esempio n. 2
0
        protected override IQueryable <TSourceData> DefaultFilter(IQueryable <TSourceData> source, RangeTuple <TVal> key)
        {
            if (_sourceExpression == null)
            {
                throw new Exception("Trying to call FilterDelegate with null source expression");
            }

            if (TreatEqualDateAsWholeDay)
            {
                if (typeof(TVal) == typeof(DateTime) || typeof(TVal) == typeof(DateTime?))
                {
                    if (key.HasFrom && key.HasTo)
                    {
                        var from = (DateTime)(object)key.From;
                        var to   = (DateTime)(object)key.To;
                        if (from.Date == to.Date)
                        {
                            key.From = (TVal)(object)new DateTime(from.Year, from.Month, from.Day, 00, 00, 00);
                            key.To   = (TVal)(object)new DateTime(from.Year, from.Month, from.Day, 23, 59, 59);
                        }
                    }
                }
            }

            if (key.HasTo && key.HasFrom)
            {
                var between = LambdaHelpers.BetweenLambdaExpression(_sourceExpression, key.From.ExtractValueFromNullable(), key.To.ExtractValueFromNullable(), _inclusive);
                return(ReflectionCache.CallWhere(source, between));
            }
            if (key.HasTo)
            {
                ExpressionType lt   = _inclusive ? ExpressionType.LessThanOrEqual : ExpressionType.LessThan;
                var            less = LambdaHelpers.ConstantBinaryLambdaExpression(lt, _sourceExpression, key.To.ExtractValueFromNullable());
                return(ReflectionCache.CallWhere(source, less));
            }
            if (key.HasFrom)
            {
                ExpressionType gt      = _inclusive ? ExpressionType.GreaterThanOrEqual : ExpressionType.GreaterThan;
                var            greater = LambdaHelpers.ConstantBinaryLambdaExpression(gt, _sourceExpression, key.From.ExtractValueFromNullable());
                return(ReflectionCache.CallWhere(source, greater));
            }
            return(source);
        }