Ejemplo n.º 1
0
        /// <exception cref="NotSupportedException" />
        /// <exception cref="InvalidOperationException" />
        private IEnumerable <T> FilterComparsion(
            Expression memberExpression, Expression keyExpression, ExpressionType type)
        {
            IComparsionIndex <T> index = FindComparsionIndex(memberExpression);

            object key = keyExpression.GetValue();

            switch (type)
            {
            case ExpressionType.GreaterThan:
                return(index.GreaterThan(key, exclusive: true));

            case ExpressionType.GreaterThanOrEqual:
                return(index.GreaterThan(key, exclusive: false));

            case ExpressionType.LessThan:
                return(index.LessThan(key, exclusive: true));

            case ExpressionType.LessThanOrEqual:
                return(index.LessThan(key, exclusive: false));

            default:
                throw new NotSupportedException($"Expression {type} should be Comparsion");
            }
        }
Ejemplo n.º 2
0
        /// <exception cref="NotSupportedException" />
        /// <exception cref="InvalidOperationException" />
        public TProperty Min <TProperty>(Expression <Func <T, TProperty> > property)
        {
            if (property == null)
            {
                throw new ArgumentNullException(nameof(property));
            }

            IComparsionIndex <T> index = FindComparsionIndex(property.Body);

            return((TProperty)index.Min());
        }
Ejemplo n.º 3
0
        /// <exception cref="NotSupportedException" />
        /// <exception cref="InvalidOperationException" />
        public IEnumerable <T> HavingMax <TProperty>(Expression <Func <T, TProperty> > property)
        {
            if (property == null)
            {
                throw new ArgumentNullException(nameof(property));
            }

            IComparsionIndex <T> index = FindComparsionIndex(property.Body);

            return(index.HavingMax());
        }
Ejemplo n.º 4
0
        /// <exception cref="NotSupportedException" />
        /// <exception cref="InvalidOperationException" />
        private IEnumerable <T> FilterStringStartsWith(MethodCallExpression methodCall)
        {
            if (methodCall.Method.DeclaringType == typeof(String) &&
                methodCall.Method.Name == nameof(String.StartsWith))
            {
                IComparsionIndex <T> index = FindComparsionIndex(methodCall.Object);

                string keyFrom = (string)methodCall.Arguments.First().GetValue();

                if (String.IsNullOrEmpty(keyFrom))
                {
                    return(index.GreaterThan(keyFrom, false));
                }

                char lastChar = keyFrom[keyFrom.Length - 1];

                string keyTo = keyFrom.Substring(0, keyFrom.Length - 1) + (char)(lastChar + 1);

                return(index.Between(keyFrom, false, keyTo, true));
            }

            throw new NotSupportedException(
                      $"Predicate body {methodCall} should be String.StartsWith()");
        }