private void CreateRangeDescriptor <T>(OperatorType operatorType,
                                               NumericRangeQueryDescriptor <T> descriptor,
                                               NumericFilterValue numericFilterValue)
            where T : class
        {
            switch (operatorType)
            {
            case OperatorType.Equal:
                descriptor.GreaterThanOrEquals(numericFilterValue.Value);
                descriptor.LessThanOrEquals(numericFilterValue.Value);
                break;

            case OperatorType.GreaterThan:
                descriptor.GreaterThan(numericFilterValue.Value);
                break;

            case OperatorType.GreaterThanOrEqual:
                descriptor.GreaterThanOrEquals(numericFilterValue.Value);
                break;

            case OperatorType.LessThan:
                descriptor.LessThan(numericFilterValue.Value);
                break;

            case OperatorType.LessThanOrEquals:
                descriptor.LessThanOrEquals(numericFilterValue.Value);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        public static NumericRangeQueryDescriptor <T> Filter <T>(this NumericRangeQueryDescriptor <T> descriptor, Filter one, Filter two) where T : class
        {
            Double fOne;

            if (!Double.TryParse(one.Value, out fOne))
            {
                throw new ArgumentException("Filter not a parsable number");
            }
            Double fTwo;

            if (!Double.TryParse(two.Value, out fTwo))
            {
                throw new ArgumentException("Filter not a parsable number");
            }

            switch (one.Operator)
            {
            case "lt":
                descriptor = descriptor.LessThan(fOne);
                break;

            case "lte":
                descriptor = descriptor.LessThanOrEquals(fOne);
                break;

            case "gt":
                descriptor = descriptor.GreaterThan(fOne);
                break;

            case "gte":
                descriptor = descriptor.GreaterThanOrEquals(fOne);
                break;
            }

            switch (two.Operator)
            {
            case "lt":
                descriptor = descriptor.LessThan(fTwo);
                break;

            case "lte":
                descriptor = descriptor.LessThanOrEquals(fTwo);
                break;

            case "gt":
                descriptor = descriptor.GreaterThan(fTwo);
                break;

            case "gte":
                descriptor = descriptor.GreaterThanOrEquals(fTwo);
                break;
            }
            return(descriptor);
        }
Esempio n. 3
0
 public static NumericRangeQueryDescriptor <T> RangeOnNumber <T>(this NumericRangeQueryDescriptor <T> filterDescriptor, ExpressionType type, double value) where T : class
 {
     if (type == ExpressionType.LessThan)
     {
         return(filterDescriptor.LessThan(value));
     }
     if (type == ExpressionType.GreaterThan)
     {
         return(filterDescriptor.GreaterThan(value));
     }
     if (type == ExpressionType.LessThanOrEqual)
     {
         return(filterDescriptor.LessThanOrEquals(value));
     }
     if (type == ExpressionType.GreaterThanOrEqual)
     {
         return(filterDescriptor.GreaterThanOrEquals(value));
     }
     throw new NotImplementedException();
 }