예제 #1
0
        /// <summary>
        /// Validate value.
        /// </summary>
        /// <param name="value">Value.</param>
        public override void Validate(object value)
        {
            if (value == null && _minLength <= 0)
            {
                return;
            }

            string str = (string)value;

            if (str == null || str.Length < _minLength)
            {
                throw new ArgumentException(APResource.GetString(APResource.APValidate_StringAtLeast, _minLength));
            }
            if (str.Length > _maxLength)
            {
                throw new ArgumentException(APResource.GetString(APResource.APValidate_StringMoreThen, _maxLength));
            }
            if (_invalidCharacters != null && str.IndexOfAny(_invalidCharacters) != -1)
            {
                throw new ArgumentException(APResource.GetString(APResource.APValidate_StringInvalidContain, _invalidCharacters));
            }
        }
예제 #2
0
        /// <summary>
        /// Validate value.
        /// </summary>
        /// <param name="value">Value.</param>
        public override void Validate(object value)
        {
            int l = (int)value;

            if (!_rangeIsExclusive)
            {
                if (l < _minValue || l > _maxValue)
                {
                    throw new ArgumentException(APResource.GetString(APResource.APValidate_NumberOutOfRange, _minValue, _maxValue));
                }
            }
            else
            {
                if (l >= _minValue && l <= _maxValue)
                {
                    throw new ArgumentException(APResource.GetString(APResource.APValidate_NumberInTheRange, _minValue, _maxValue));
                }
            }
            if (_resolution != 0 && l % _resolution != 0)
            {
                throw new ArgumentException(APResource.GetString(APResource.APValidate_NumberInTheRange, _resolution));
            }
        }