/// <summary> /// Adds a Then clause to a Rule the Reports a <see cref="RuleViolation"/>. /// </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="message">Message to use in <see cref="RuleViolation"/></param> /// <param name="nameDictionary"><see cref="IDictionary{TKey,TValue}"/> to use when formating the <paramref name="message"/></param> /// <param name="propertyNames">Params of propertyNames that caused the rule violation.</param> /// <returns> /// A <see cref="IPropertyRuleBuilder{TContext,TSubject,TProperty}"/>. /// </returns> public static IPropertyRuleBuilder <TContext, TSubject, TProperty> ThenReportRuleViolation <TSubject, TContext, TProperty> ( this IPropertyRuleBuilder <TContext, TSubject, TProperty> propertyRuleBuilder, string message, IDictionary <string, string> nameDictionary = null, params string[] propertyNames) where TContext : RuleEngineContext <TSubject> { propertyRuleBuilder.Then( (s, ctx) => { var formattedMessage = message.FormatRuleEngineMessage( ctx.NameProvider.GetName( s, (Expression <Func <TSubject, TProperty> >)propertyRuleBuilder.PropertyRule.PropertyExpression), nameDictionary); ctx.RuleViolationReporter.Report( new RuleViolation(propertyRuleBuilder.PropertyRule, s, formattedMessage, propertyNames)); }); return(propertyRuleBuilder); }