/// <inheritdoc/> public void WithRuleCollection <T> (IRuleCollection <T> ruleCollection, IRuleSelector ruleSelector = null) { _ruleSelector = ruleSelector; var ruleEngine = new RuleEngine <T> (ruleCollection); _executeRules = ctx => ruleEngine.ExecuteRules(ctx); }
/// <summary> /// Adds a WhenClause to the rule that checks the context object against a rule collection that returns true if a rule violation occurs from rule collection. /// </summary> /// <typeparam name="TContext">The type of the context.</typeparam> /// <typeparam name="TSubject">The type of the subject.</typeparam> /// <typeparam name="TContextObject">The type of the context object.</typeparam> /// <param name="ruleBuilder">The rule builder.</param> /// <param name="ruleCollection">The rule collection.</param> /// <param name="ruleSelector">The rule selector.</param> /// <returns> /// A <see cref="IRuleBuilder{TContext,TSubject}"/> /// </returns> public static IRuleBuilder <TContext, TSubject> WithCollection <TContext, TSubject, TContextObject> ( this IContextObjectProviderRuleBuilder <TContext, TSubject, TContextObject> ruleBuilder, IRuleCollection <TContextObject> ruleCollection, IRuleSelector ruleSelector = null) where TContext : RuleEngineContext <TSubject> { ruleBuilder.Constrain(new RuleCollectionConstraint <TContextObject> (ruleCollection, ruleSelector)); return(ruleBuilder); }
/// <summary> /// Adds an <see cref="InlineConstraint{TProperty}"/> to a rule. /// </summary> /// <typeparam name="TSubject">Type of subject of the rule.</typeparam> /// <typeparam name="TContext">Type of <see cref="IRuleEngineContext"/> of the rule.</typeparam> /// <typeparam name="TProperty">Type of property of the subject of the rule.</typeparam> /// <param name="propertyRuleBuilder"><see cref="IPropertyRuleBuilder{TContext,TSubject,TProperty}"/> currently configuring the rule.</param> /// <param name="ruleCollection">Rule Collection for property.</param> /// <param name="ruleSelector">Optional Rule Selector for <paramref name="ruleCollection"/></param> /// <returns>A <see cref="IPropertyRuleBuilder{TContext,TSubject,TProperty}"/>.</returns> public static IPropertyRuleBuilder <TContext, TSubject, TProperty> ConstrainWithCollection <TSubject, TContext, TProperty> ( this IPropertyRuleBuilder <TContext, TSubject, TProperty> propertyRuleBuilder, IRuleCollection <TProperty> ruleCollection, IRuleSelector ruleSelector = null) where TContext : RuleEngineContext <TSubject> { propertyRuleBuilder.Constrain(new RuleCollectionConstraint <TProperty> (ruleCollection, ruleSelector)); return(propertyRuleBuilder); }
/// <summary> /// Initializes a new instance of the <see cref="RuleEngineContext<TSubject>"/> class. /// </summary> /// <param name="subject">Subject for the context.</param> /// <param name="ruleViolationReporter"><see cref="IRuleViolationReporter">RuleViolationReporter</see> of the context.</param> /// <param name="ruleSelector"><see cref="IRuleSelector">RuleSelector</see> of the context.</param> /// <param name="nameProvider"><see cref="INameProvider">NameProvider</see> of the context.</param> /// <param name="parentContext">Optional Parent RuleEngineContext.</param> public RuleEngineContext( TSubject subject, IRuleViolationReporter ruleViolationReporter, IRuleSelector ruleSelector, INameProvider nameProvider, IRuleEngineContext parentContext = null) : base(subject, ruleViolationReporter, ruleSelector, nameProvider, parentContext) { Subject = subject; }
/// <summary> /// Initializes a new instance of the <see cref="RuleCollectionConstraint<TProperty>"/> class. /// </summary> /// <param name="ruleCollection">Rule Collection property must satisfy.</param> /// <param name="ruleSelector">Optional Rule selector for selecting rules in <paramref name="ruleCollection"/></param> public RuleCollectionConstraint(IRuleCollection <TProperty> ruleCollection, IRuleSelector ruleSelector = null) : base(null) { _ruleCollection = ruleCollection; _ruleSelector = ruleSelector; }
/// <summary> /// Initializes a new instance of the <see cref="RuleCommandInfo"/> class. /// </summary> /// <param name="owner">The owner of the command.</param> /// <param name="name">The name of the command.</param> /// <param name="ruleSelector">The rule selector.</param> public RuleCommandInfo(object owner, string name, IRuleSelector ruleSelector) : base(owner, name) { RuleSelector = ruleSelector; }
/// <summary> /// Exectutes rules selected by the rule selector in the Rule Collection of the Rule Engine. /// </summary> /// <param name="subject">Subject the rules are run against.</param> /// <param name="ruleSelector">The <see cref="IRuleSelector">Rule Selector</see> to determin the list of rules that will be executed.</param> /// <returns>A <see cref="RuleExecutionResult"/> containing the results of the execution pass.</returns> public RuleExecutionResult ExecuteSelectedRules(TSubject subject, IRuleSelector ruleSelector) { var ruleEngineContext = new RuleEngineContext <TSubject> (subject, ruleSelector); return(ExecuteRules(ruleEngineContext)); }
/// <summary> /// Initializes a new instance of the <see cref="RuleCommandInfo"/> class. /// </summary> /// <param name="owner">The owner of the command.</param> /// <param name="name">The name of the command.</param> /// <param name="ruleSelector">The rule selector.</param> public RuleCommandInfo( object owner, string name, IRuleSelector ruleSelector ) : base(owner, name) { RuleSelector = ruleSelector; }
/// <summary> /// Initializes a new instance of the <see cref="RuleEngineContext<TSubject>"/> class. /// </summary> /// <param name="subject">Subject for the context.</param> /// <param name="ruleViolationReporter"><see cref="IRuleViolationReporter">RuleViolationReporter</see> of the context.</param> /// <param name="ruleSelector"><see cref="IRuleSelector">RuleSelector</see> of the context.</param> /// <param name="parentContext">Optional Parent RuleEngineContext.</param> public RuleEngineContext( TSubject subject, IRuleViolationReporter ruleViolationReporter, IRuleSelector ruleSelector, IRuleEngineContext parentContext = null) : this(subject, ruleViolationReporter, ruleSelector, null, parentContext) { }
/// <summary> /// Initializes a new instance of the <see cref="RuleEngineContext<TSubject>"/> class. /// </summary> /// <param name="subject">Subject for the context.</param> /// <param name="ruleSelector"><see cref="IRuleSelector">RuleSelector</see> of the context.</param> /// <param name="nameProvider"><see cref="INameProvider">NameProvider</see> of the context.</param> /// <param name="parentContext">Optional Parent RuleEngineContext.</param> public RuleEngineContext(TSubject subject, IRuleSelector ruleSelector, INameProvider nameProvider, IRuleEngineContext parentContext = null) : this(subject, new RuleViolationCollection(), ruleSelector, nameProvider, parentContext) { }
/// <inheritdoc/> public ICollectionPropertyRuleBuilder <TContext, TSubject, TProperty> WithRuleCollection( IRuleCollection <TProperty> ruleCollection, IRuleSelector ruleSelector = null) { _collectionPropertyRule.WithRuleCollection(ruleCollection, ruleSelector); return(this); }