/// <summary> /// Initializes a new instance of the <see cref="DelegateCommand" /> class. /// </summary> /// <param name="execute">The execute.</param> /// <param name="canExecute">The can execute.</param> public DelegateCommand(Action execute, Func <bool> canExecute) : this(execute) { canExecute.Guard("canExecute"); this.canExecute = canExecute; }
/// <summary> /// Initializes a new instance of the <see cref="ParameterizedThreadedResultWorker{TArgs,TResult}" /> class. /// </summary> /// <param name="target">The target.</param> /// <param name="logger">The logger.</param> /// <param name="apartmentState">State of the apartment.</param> public ParameterizedThreadedResultWorker(Func <TArgs, TResult> target, ILogger logger, ApartmentState apartmentState = ApartmentState.MTA) : base(logger, apartmentState) { target.Guard("target"); this.target = target; }
/// <summary> /// Defines a predicate validator on the current rule builder using a lambda expression to specify the predicate. /// Validation will fail if the specified lambda returns false. /// Validation will succeed if the specifed lambda returns true. /// This overload accepts the object being validated in addition to the property being validated. /// </summary> /// <typeparam name="T">Type of object being validated</typeparam> /// <typeparam name="TProperty">Type of property being validated</typeparam> /// <param name="ruleBuilder">The rule builder on which the validator should be defined</param> /// <param name="predicate">A lambda expression specifying the predicate</param> /// <returns></returns> public static IRuleBuilderOptions <T, TProperty> Must <T, TProperty>(this IRuleBuilder <T, TProperty> ruleBuilder, Func <T, TProperty, PropertyValidatorContext, bool> predicate) { predicate.Guard("Cannot pass a null predicate to Must."); return(ruleBuilder.SetValidator(new PredicateValidator((instance, property, propertyValidatorContext) => predicate((T)instance, (TProperty)property, propertyValidatorContext)))); }
/// <summary> /// Specifies an asynchronous condition limiting when the validator should not run. /// The validator will only be executed if the result of the lambda returns false. /// </summary> /// <param name="rule">The current rule</param> /// <param name="predicate">A lambda expression that specifies a condition for when the validator should not run</param> /// <param name="applyConditionTo">Whether the condition should be applied to the current rule or all rules in the chain</param> /// <returns></returns> public static IRuleBuilderOptions <T, TProperty> UnlessAsync <T, TProperty>(this IRuleBuilderOptions <T, TProperty> rule, Func <T, Task <bool> > predicate, ApplyConditionTo applyConditionTo = ApplyConditionTo.AllValidators) { predicate.Guard("A predicate must be specified when calling UnlessAsync"); return(rule.WhenAsync(x => predicate(x).Then(y => !y), applyConditionTo)); }
/// <summary> /// Specifies a condition limiting when the validator should run. /// The validator will only be executed if the result of the lambda returns true. /// </summary> /// <param name="rule">The current rule</param> /// <param name="predicate">A lambda expression that specifies a condition for when the validator should run</param> /// <param name="applyConditionTo">Whether the condition should be applied to the current rule or all rules in the chain</param> /// <returns></returns> public static IRuleBuilderOptionsConditions <T, TProperty> When <T, TProperty>(this IRuleBuilderOptionsConditions <T, TProperty> rule, Func <T, bool> predicate, ApplyConditionTo applyConditionTo = ApplyConditionTo.AllValidators) { predicate.Guard("A predicate must be specified when calling When.", nameof(predicate)); return(rule.When((x, ctx) => predicate(x), applyConditionTo)); }
/// <summary> /// Initializes a new instance of the <see cref="ParameterizedThreadedResultWorker{TArgs,TResult}" /> class. /// </summary> /// <param name="target">The target.</param> /// <param name="logger">The logger.</param> /// <param name="apartmentState">State of the apartment.</param> /// <param name="isBackgroundThread"></param> public ParameterizedThreadedResultWorker(Func <TArgs, TResult> target, ILogger logger, ApartmentState apartmentState = ApartmentState.MTA, bool isBackgroundThread = true) : base(logger, apartmentState, isBackgroundThread) { target.Guard("target"); this.target = target; }
public void CustomAsync(Func <T, Task <ValidationFailure> > customValidator) { customValidator.Guard("Cannot pass null to Custom"); AddRule(new DelegateValidator <T>(x => customValidator(x).Then(f => new[] { f }.AsEnumerable(), runSynchronously: true))); }
/// <summary> /// Creates a new ASyncPredicateValidator /// </summary> /// <param name="predicate"></param> public AsyncPredicateValidator(Func <object, object, PropertyValidatorContext, CancellationToken, Task <bool> > predicate) { predicate.Guard("A predicate must be specified."); this.predicate = predicate; }
public ILoopCondition <T> ExitWhen(Func <T, bool> exit) { exit.Guard("Exit delegate must not be null."); Exit = exit; return(this); }
/// <summary> /// Defines a predicate validator on the current rule builder using a lambda expression to specify the predicate. /// Validation will fail if the specified lambda returns false. /// Validation will succeed if the specified lambda returns true. /// </summary> /// <typeparam name="T">Type of object being validated</typeparam> /// <typeparam name="TProperty">Type of property being validated</typeparam> /// <param name="ruleBuilder">The rule builder on which the validator should be defined</param> /// <param name="predicate">A lambda expression specifying the predicate</param> /// <returns></returns> public static IRuleBuilderOptions <T, TProperty> Must <T, TProperty>(this IRuleBuilder <T, TProperty> ruleBuilder, Func <TProperty, bool> predicate) { predicate.Guard("Cannot pass a null predicate to Must.", nameof(predicate)); return(ruleBuilder.Must((x, val) => predicate(val))); }
/// <summary> /// Initializes a new instance of the <see cref="DelegateCommand" /> class. /// </summary> /// <param name="execute">The execute.</param> /// <param name="canExecute">The can execute.</param> public DelegateCommand(Action execute, Func<bool> canExecute) : this(execute) { canExecute.Guard("canExecute"); this.canExecute = canExecute; }
public DomainCircuitBreaker(Func <IDomainService> domainServiceFactory) { _domainServiceFactory = domainServiceFactory.Guard(nameof(domainServiceFactory)); }
public AsyncPredicateValidator(Func <object, object, PropertyValidatorContext, Task <bool> > predicate) : base(() => Messages.predicate_error) { predicate.Guard("A predicate must be specified."); this.predicate = predicate; }
/// <summary> /// Defines an asynchronous predicate validator on the current rule builder using a lambda expression to specify the predicate. /// Validation will fail if the specified lambda returns false. /// Validation will succeed if the specifed lambda returns true. /// </summary> /// <typeparam name="T">Type of object being validated</typeparam> /// <typeparam name="TProperty">Type of property being validated</typeparam> /// <param name="ruleBuilder">The rule builder on which the validator should be defined</param> /// <param name="predicate">A lambda expression specifying the predicate</param> /// <returns></returns> public static IRuleBuilderOptions <T, TProperty> MustAsync <T, TProperty>(this IRuleBuilder <T, TProperty> ruleBuilder, Func <TProperty, Task <bool> > predicate) { predicate.Guard("Cannot pass a null predicate to Must."); return(ruleBuilder.MustAsync((x, val) => predicate(val))); }
/// <summary> /// Specifies an asynchronous condition limiting when the validator should not run. /// The validator will only be executed if the result of the lambda returns false. /// </summary> /// <param name="rule">The current rule</param> /// <param name="predicate">A lambda expression that specifies a condition for when the validator should not run</param> /// <param name="applyConditionTo">Whether the condition should be applied to the current rule or all rules in the chain</param> /// <returns></returns> public static IRuleBuilderOptions <T, TProperty> UnlessAsync <T, TProperty>(this IRuleBuilderOptions <T, TProperty> rule, Func <T, CancellationToken, Task <bool> > predicate, ApplyConditionTo applyConditionTo = ApplyConditionTo.AllValidators) { predicate.Guard("A predicate must be specified when calling UnlessAsync", nameof(predicate)); return(rule.WhenAsync(async(x, ct) => !await predicate(x, ct), applyConditionTo)); }
public ILoopCondition <T> SkipWhen(Func <T, bool> skip) { skip.Guard("Skip delegate must not be null"); Continue = skip; return(this); }
/// <summary> /// Creates a new AsyncPredicateValidator /// </summary> /// <param name="predicate"></param> public AsyncPredicateValidator(Func <object, object, PropertyValidatorContext, CancellationToken, Task <bool> > predicate) : base(new LanguageStringSource(nameof(AsyncPredicateValidator))) { predicate.Guard("A predicate must be specified.", nameof(predicate)); this._predicate = predicate; }
/// <summary> /// Creates a new ASyncPredicateValidator /// </summary> /// <param name="predicate"></param> public AsyncPredicateValidator(Func <object, object, PropertyValidatorContext, CancellationToken, Task <bool> > predicate) : base(nameof(Messages.predicate_error), typeof(Messages)) { predicate.Guard("A predicate must be specified."); this.predicate = predicate; }
public void Custom(Func <T, ValidationContext <T>, ValidationFailure> customValidator) { customValidator.Guard("Cannot pass null to Custom"); AddRule(new DelegateValidator <T>((x, ctx) => new[] { customValidator(x, ctx) })); }
/// <summary> /// Sets the validator associated with the rule. Use with complex properties where an IValidator instance is already declared for the property type. /// </summary> /// <param name="validatorProvider">The validator provider to set</param> public IRuleBuilderOptions <T, TProperty> SetValidator <TValidator>(Func <ICommonContext, TValidator> validatorProvider) where TValidator : IValidator <TProperty> { validatorProvider.Guard("Cannot pass a null validatorProvider to SetValidator", nameof(validatorProvider)); SetValidator(new ChildValidatorAdaptor <T, TProperty>(context => validatorProvider(context), typeof(TValidator))); return(this); }
public void CustomAsync(Func <T, ValidationContext <T>, CancellationToken, Task <ValidationFailure> > customValidator) { customValidator.Guard("Cannot pass null to Custom"); AddRule(new DelegateValidator <T>((x, ctx, cancel) => customValidator(x, ctx, cancel).Then(f => new[] { f }.AsEnumerable(), runSynchronously: true))); }
public ICollectionValidatorRuleBuilder <T, TCollectionElement> Where(Func <TCollectionElement, bool> predicate) { predicate.Guard("Cannot pass null to Where."); adaptor.Predicate = x => predicate((TCollectionElement)x); return(this); }
/// <summary> /// Specifies custom state that should be stored alongside the validation message when validation fails for this rule. /// </summary> /// <typeparam name="T"></typeparam> /// <typeparam name="TProperty"></typeparam> /// <param name="rule"></param> /// <param name="stateProvider"></param> /// <returns></returns> public static IRuleBuilderOptions <T, TProperty> WithState <T, TProperty>(this IRuleBuilderOptions <T, TProperty> rule, Func <T, object> stateProvider) { stateProvider.Guard("A lambda expression must be passed to WithState"); return(rule.Configure(config => config.CurrentValidator.CustomStateProvider = stateProvider.CoerceToNonGeneric())); }
/// <summary> /// Defines a predicate validator on the current rule builder using a lambda expression to specify the predicate. /// Validation will fail if the specified lambda returns false. /// Validation will succeed if the specifed lambda returns true. /// This overload accepts the object being validated in addition to the property being validated. /// </summary> /// <typeparam name="T">Type of object being validated</typeparam> /// <typeparam name="TProperty">Type of property being validated</typeparam> /// <param name="ruleBuilder">The rule builder on which the validator should be defined</param> /// <param name="predicate">A lambda expression specifying the predicate</param> /// <returns></returns> public static IRuleBuilderOptions <T, TProperty> Must <T, TProperty>(this IRuleBuilder <T, TProperty> ruleBuilder, Func <T, TProperty, bool> predicate) { predicate.Guard("Cannot pass a null predicate to Must."); return(ruleBuilder.Must((x, val, propertyValidatorContext) => predicate(x, val))); }
public AsyncPredicateValidator(Func<object, object, PropertyValidatorContext, CancellationToken, Task<bool>> predicate) : base(() => Messages.predicate_error) { predicate.Guard("A predicate must be specified."); this.predicate = predicate; }
/// <summary> /// Creates a new AsyncPredicateValidator /// </summary> /// <param name="predicate"></param> public AsyncPredicateValidator(Func <T, TProperty, ValidationContext <T>, CancellationToken, Task <bool> > predicate) { predicate.Guard("A predicate must be specified.", nameof(predicate)); this._predicate = predicate; }