예제 #1
0
        /// <inheritdoc/>
        protected override void OnEnter()
        {
            Result = new RangeValue();

            _leftBoundary  = new RangeBoundary();
            _rightBoundary = new RangeBoundary();
        }
예제 #2
0
 public RangeValidator(dynamic minimum, dynamic maximum, RangeBoundary lowerBoundary = RangeBoundary.Include, RangeBoundary upperBoundary = RangeBoundary.Include)
 {
     Minimum        = minimum;
     Maximum        = maximum;
     _lowerBoundary = lowerBoundary;
     _upperBoundary = upperBoundary;
     _errorMessage  = "value out of range";
 }
예제 #3
0
        /// <summary>
        /// Range
        /// </summary>
        /// <typeparam name="T">DataType</typeparam>
        public static void Range <T>(dynamic minimum, dynamic maximum, RangeBoundary lowerBoundary = RangeBoundary.Include, RangeBoundary upperBoundary = RangeBoundary.Include, params ValidationField <T>[] fields)
        {
            string        validatorKey = string.Format("{0}/{1}_{2}_{3}_{4}", typeof(RangeValidator).FullName, minimum, maximum, (int)lowerBoundary, (int)upperBoundary);
            DataValidator validator    = null;

            if (_validatorList.ContainsKey(validatorKey))
            {
                validator = _validatorList[validatorKey];
            }
            else
            {
                validator = new RangeValidator(minimum, maximum, lowerBoundary, upperBoundary);
                _validatorList.Add(validatorKey, validator);
            }
            SetValidation <T>(validator, fields);
        }
예제 #4
0
        private static void TstRangeValue()
        {
            _logger.Log("Begin");

            var leftValue = new NumberValue(0);

            var leftBoundary = new RangeBoundary();

            leftBoundary.Value    = leftValue;
            leftBoundary.Includes = true;

            var rightValue = new NumberValue(12);

            var rightBoundary = new RangeBoundary();

            rightBoundary.Value    = rightValue;
            rightBoundary.Includes = true;

            var range = new RangeValue();

            range.LeftBoundary  = leftBoundary;
            range.RightBoundary = rightBoundary;

            range.CheckDirty();

            _logger.Log($"range = {range}");

            _logger.Log($"range.ToDbgString() = {range.ToDbgString()}");

            _logger.Log($"range.Length = {range.Length}");

            _logger.Log($"range.IsFit(-1) = {range.IsFit(-1)}");
            _logger.Log($"range.IsFit(0) = {range.IsFit(0)}");
            _logger.Log($"range.IsFit(1) = {range.IsFit(1)}");
            _logger.Log($"range.IsFit(12) = {range.IsFit(12)}");
            _logger.Log($"range.IsFit(14) = {range.IsFit(14)}");

            _logger.Log("End");
        }
예제 #5
0
 /// <summary>
 /// Build range validation
 /// </summary>
 /// <param name="modelType">Model type</param>
 /// <param name="minValue">Min value</param>
 /// <param name="maxValue">Max value</param>
 /// <param name="lowerBoundary">Lower boundary</param>
 /// <param name="upperBoundary">Upper boundary</param>
 /// <param name="valueFieldArray">Value field array</param>
 void BuildRangeValidation(Type modelType, dynamic minValue, dynamic maxValue, RangeBoundary lowerBoundary, RangeBoundary upperBoundary, Array valueFieldArray)
 {
     MethodInfo rangeMethod = ValidationMethods.FirstOrDefault(c => c.Name == "Range");
     if (rangeMethod == null)
     {
         return;
     }
     rangeMethod.MakeGenericMethod(modelType).Invoke(null, new object[]
     {
         minValue,maxValue,lowerBoundary,upperBoundary,valueFieldArray
     });
 }