/// <summary> /// 验证对象数据,可指定验证某些属性 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="validator"></param> /// <param name="instance"></param> /// <param name="propertyExpressions"></param> /// <returns></returns> public ValidationResult Validate <TEntity>(IDatabase database, TEntity instance, params Expression <Func <TEntity, object> >[] propertyExpressions) { ValidInstance(instance, false); var selector = ValidatorOptions.ValidatorSelectors.MemberNameValidatorSelectorFactory(MemberNameValidatorSelector.MemberNamesFromExpressions(propertyExpressions)); var context = new ValidationContext <TEntity>(database, instance, new PropertyChain(), selector); return(ValidateInternal(context)); }
/// <summary> /// Validates certain properties of the specified instance asynchronously. /// </summary> /// <param name="validator">The current validator</param> /// <param name="instance">The object to validate</param> /// <param name="cancellationToken"></param> /// <param name="properties">Expressions to specify the properties to validate</param> public static void Validate <T> (this IReactiveValidator <T> validator, T instance, CancellationToken cancellationToken = default, params Expression <Func <T, object?> > [] properties) where T : class { var selector = ValidatorOptions.Global.ValidatorSelectors.MemberNameValidatorSelectorFactory(MemberNameValidatorSelector.MemberNamesFromExpressions(properties)); var context = new ValidationContext <T> (instance, new PropertyChain( ), selector); validator.Validate(context, cancellationToken); }