Example #1
0
        /// <summary>
        /// Validate data
        /// </summary>
        /// <returns>Return the verify result</returns>
        public VerifyResult Validate(dynamic data)
        {
            if (valueMethod == null || validator == null)
            {
                return(VerifyResult.SuccessResult());
            }
            dynamic value = valueMethod(data);

            if (validator is CompareValidator)
            {
                CompareVerificationValue operatorValue = new CompareVerificationValue()
                {
                    SourceValue = value
                };
                if (compareValue is Func <T, dynamic> )
                {
                    operatorValue.CompareValue = ((Func <T, dynamic>)compareValue)(data);
                }
                else
                {
                    operatorValue.CompareValue = compareValue;
                }
                validator.Validate(operatorValue, errorMessage);
            }
            else
            {
                validator.Validate(value, errorMessage);
            }
            validator.Result.FieldName = fieldName;
            return(validator.Result);
        }
Example #2
0
 /// <summary>
 /// Set verify result
 /// </summary>
 /// <param name="isValid">Is valid</param>
 /// <param name="message">Message</param>
 protected void SetVerifyResult(bool isValid, string message = "")
 {
     this.isValid = isValid;
     verifyResult = this.isValid ? VerifyResult.SuccessResult() : VerifyResult.ErrorResult(FormatMessage(message));
 }