/// <summary> /// Initializes a new instance of the <see cref="EntityPropertyValidationRule{TEntity, TProperty}"/> class. /// </summary> /// <param name="validator">The validator.</param> /// <param name="propertyDisplayNameResolver">The property display name resolver.</param> /// <param name="propertyExpression">The property expression.</param> /// <param name="specification">The specification.</param> /// <param name="message">The message.</param> public EntityPropertyValidationRule(IEntityPropertyValidator validator, IPropertyDisplayNameResolver propertyDisplayNameResolver, Expression <Func <TEntity, TProperty> > propertyExpression, ISpecification <TEntity> specification = null, string message = null) { if (validator == null) { throw new ArgumentNullException("validator"); } if (propertyDisplayNameResolver == null) { throw new ArgumentNullException("propertyDisplayNameResolver"); } if (propertyExpression == null) { throw new ArgumentNullException("propertyExpression"); } m_Validator = validator; m_PropertyDisplayNameResolver = propertyDisplayNameResolver; m_Specification = specification; m_Message = message; m_PropertyFunc = propertyExpression.Compile(); m_MemberInfo = LinqUtils.GetMemberInfo(propertyExpression); }
/// <summary> /// When implemented in a derived class, returns metadata for client validation. /// </summary> /// <returns> /// The metadata for client validation. /// </returns> public override IEnumerable <ModelClientValidationRule> GetClientValidationRules() { IEntityValidationRule entityValidationRule = ValidationRule; IEntityPropertyValidator entityPropertyValidator = entityValidationRule.Validator; ValidatorProperties validatorProperties = entityPropertyValidator.GetValidatorProperties(); string message = entityValidationRule.GetValidationMessage(Metadata.Model); yield return(new ModelClientValidationRegexRule(message, validatorProperties.GetPropertyValue <string>(Constants.ValidationMessageParameterNames.REGEX))); }
/// <summary> /// Sets the validator. /// </summary> /// <param name="validator">The validator.</param> /// <returns>The entity validation rule builder.</returns> public IEntityValidationRuleBuilder <TEntity, TProperty> AddValidator(IEntityPropertyValidator validator) { if (validator == null) { throw new ArgumentNullException("validator"); } m_Validators.Add(validator); return(this); }
/// <summary> /// Initializes a new instance of the <see cref="StubEntityValidationRule"/> class. /// </summary> /// <param name="validator">The validator.</param> /// <param name="displayName">The member info.</param> /// <param name="propertyName">The property name.</param> /// <exception cref="System.ArgumentNullException"> /// validator /// or /// propertyDisplayNameResolver /// or /// propertyExpression /// </exception> public StubEntityValidationRule(IEntityPropertyValidator validator, string displayName, string propertyName) { if (validator == null) { throw new ArgumentNullException("validator"); } m_Validator = validator; m_DisplayName = displayName; m_PropertyName = propertyName; }
/// <summary> /// Builds the entity validation rule. /// </summary> /// <param name="ruleSetName">Name of the rule set.</param> public void Build(string ruleSetName) { if (ruleSetName == null) { throw new ArgumentNullException("ruleSetName"); } for (int i = 0; i < m_Validators.Count; i++) { IEntityPropertyValidator validator = m_Validators[i]; m_EntityValidatorBase.AddRule(ruleSetName, new EntityPropertyValidationRule <TEntity, TProperty>(validator, m_PropertyDisplayNameResolver, m_PropertyExpression, m_Specification, m_Message)); } }
public ResourcePreprocessService( IValidationService shaclValidationService, IMapper mapper, IResourceRepository resourceRepository, IMetadataService metadataService, IIdentifierValidationService identifierValidationService, IMetadataGraphConfigurationService metadataConfigService, ILogger <ResourcePreprocessService> logger, IEntityPropertyValidator entityPropertyValidator) { _validationService = shaclValidationService; _mapper = mapper; _metadataService = metadataService; _metadataConfigService = metadataConfigService; _resourceRepository = resourceRepository; _logger = logger; _entityPropertyValidator = entityPropertyValidator; _identifierValidationService = identifierValidationService; }