public override void Validate(object value) { ValidatorUtils.HelperParamValidation(value, typeof(string)); string data = value as string; int len = data?.Length ?? 0; if (len < _minLength) { throw new ArgumentException(string.Format(SR.Validator_string_min_length, _minLength)); } if (len > _maxLength) { throw new ArgumentException(string.Format(SR.Validator_string_max_length, _maxLength)); } // Check if the string contains any invalid characters if ((len > 0) && !string.IsNullOrEmpty(_invalidChars)) { char[] array = new char[_invalidChars.Length]; _invalidChars.CopyTo(0, array, 0, _invalidChars.Length); if (data.IndexOfAny(array) != -1) { throw new ArgumentException(string.Format(SR.Validator_string_invalid_chars, _invalidChars)); } } }
public override void Validate(object value) { ValidatorUtils.HelperParamValidation(value, typeof(TimeSpan)); ValidatorUtils.ValidateScalar((TimeSpan)value, _minValue, _maxValue, _resolution, _flags == ValidationFlags.ExclusiveRange); }
public void HelperParamValidation(object value, Type allowedType, bool shouldThrow) { Action action = () => ValidatorUtils.HelperParamValidation(value, allowedType); if (!shouldThrow) { action(); } else { Assert.Throws <ArgumentException>(action); } }
public override void Validate(object value) { if (value == null) { return; } // Make a check here since value.GetType() returns RuntimeType rather then Type if (!(value is Type)) { ValidatorUtils.HelperParamValidation(value, typeof(Type)); } if (!_base.IsAssignableFrom((Type)value)) { throw new ArgumentException(SR.Format(SR.Subclass_validator_error, ((Type)value).FullName, _base.FullName)); } }