/// <summary> /// Validates certain properties of the specified instance asynchronously. /// </summary> /// <param name="validator"></param> /// <param name="instance">The object to validate</param> /// <param name="cancellationToken"></param> /// <param name="properties">The names of the properties to validate.</param> public static void Validate <T> (this IReactiveValidator <T> validator, T instance, CancellationToken cancellationToken = default, params string [] properties) where T : class { var selector = ValidatorOptions.Global.ValidatorSelectors.MemberNameValidatorSelectorFactory(properties); var context = new ValidationContext <T> (instance, new PropertyChain( ), selector); validator.Validate(context, cancellationToken); }
public static void Validate <T> (this IReactiveValidator <T> validator, T instance, CancellationToken cancellationToken = default, IValidatorSelector?selector = null, string?ruleSet = null) where T : class { if (selector != null && ruleSet != null) { throw new InvalidOperationException("Cannot specify both an IValidatorSelector and a RuleSet."); } selector ??= ValidatorOptions.Global.ValidatorSelectors.DefaultValidatorSelectorFactory( ); if (ruleSet != null) { var ruleSetNames = ruleSet.Split(',', ';'); selector = ValidatorOptions.Global.ValidatorSelectors.RulesetValidatorSelectorFactory(ruleSetNames); } var context = new ValidationContext <T> (instance, new PropertyChain( ), selector); validator.Validate(context, cancellationToken); }