MvvmValidation.Internal.ValidationRule.Evaluate C# (CSharp) Method

Evaluate() public method

public Evaluate ( ) : RuleResult
return RuleResult
        public RuleResult Evaluate()
        {
            if (!SupportsSyncValidation)
            {
                throw new NotSupportedException(
                    "Synchronous validation is not supported by this rule. Method EvaluateAsync must be called instead.");
            }

            RuleResult result = ValidateDelegate();

            return result;
        }

Usage Example

        private async Task<bool> ExecuteRuleAsync(ValidationRule rule, ISet<object> failedTargets, ValidationResult validationResultAccumulator, SynchronizationContext syncContext)
        {
            // Skip rule if the target is already invalid and the rule is not configured to execute anyway
            if (failedTargets.Contains(rule.Target) && !ShouldExecuteOnAlreadyInvalidTarget(rule))
            {
                // Assume that the rule is valid at this point because we are not interested in this error until
                // previous rule is fixed.
                SaveRuleValidationResultAndNotifyIfNeeded(rule, RuleResult.Valid(), syncContext);

                return true;
            }

            var ruleResult = !rule.SupportsSyncValidation
                ? await rule.EvaluateAsync().ConfigureAwait(false)
                : rule.Evaluate();

            SaveRuleValidationResultAndNotifyIfNeeded(rule, ruleResult, syncContext);

            AddErrorsFromRuleResult(validationResultAccumulator, rule, ruleResult);

            if (!ruleResult.IsValid)
            {
                failedTargets.Add(rule.Target);
            }

            return true;
        }
All Usage Examples Of MvvmValidation.Internal.ValidationRule::Evaluate