Exemplo n.º 1
0
        /// <summary>
        /// Document format/rules validation method
        /// </summary>
        /// <param name="property">String property being validated</param>
        /// <param name="rule">DocumentDefition rule being used</param>
        /// <param name="message">ErrorMessage</param>
        /// <returns>Validation context</returns>
        public ValidationResult <TModel> Rule(Expression <Func <TModel, string> > property, DocumentDefinition rule, string message = null)
        {
            if (this._breakIfIsInvalid && !this.Success)
            {
                return(this);
            }

            this._breakIfIsInvalid = false;

            if (!GetMember(property, out var member))
            {
                return(this);
            }

            var index = 0;

            foreach (var value in this.Values)
            {
                var propertyValue = value.GetPropertyValue <string>(member.Name);
                this.AddItem(rule.Validate(propertyValue), message, member.Name, member.Name, index);
                index++;
            }

            return(this);
        }
Exemplo n.º 2
0
 public static bool ValidateDocument(this string value, DocumentDefinition definition)
 {
     return(definition.Validate(value));
 }