/// <summary> /// Creates the length validator instance. /// </summary> /// <param name="attribute">Validation attribute.</param> /// <returns>The instance of <see cref="LengthValidator"/> class.</returns> private static IDomainModelValidator CreateLengthValidator(ValidateAttributeBase attribute) { var lengthAttribute = (ValidateLengthAttribute)attribute; lengthAttribute.CheckConsistency(); var validator = lengthAttribute.IsRequiredLengthMode ? new LengthValidator(lengthAttribute.Is) : new LengthValidator(lengthAttribute.Min, lengthAttribute.Max); if(lengthAttribute.TooShort != null) validator.TooShortMessage = lengthAttribute.TooShort; if(lengthAttribute.TooLong != null) validator.TooLongMessage = lengthAttribute.TooLong; if(lengthAttribute.WrongLength != null) validator.WrongLengthMessage = lengthAttribute.WrongLength; return validator; }
/// <summary> /// Creates the presence validator instance. /// </summary> /// <param name="attribute">Validation attribute.</param> /// <returns>The instance of <see cref="PresenceValidator"/> class.</returns> private static IDomainModelValidator CreatePresenceValidator(ValidateAttributeBase attribute) { var validateAttr = (ValidateAttribute)attribute; return (validateAttr.Presence ? new PresenceValidator() : null); }