/// <summary> /// Invokes all rule methods associated with /// the specified property. /// </summary> /// <param name="propertyName">The name of the property to validate.</param> public void CheckRules(string propertyName) { List <RuleMethod> list; // get the list of rules to check if (RulesList.ContainsKey(propertyName)) { list = RulesList[propertyName]; if (list == null) { return; } // now check the rules foreach (RuleMethod rule in list) { if (rule.Invoke()) { BrokenRulesList.Remove(rule); } else { BrokenRulesList.Add(rule); } } } }
/// <summary> /// Provides a method to aggregate BrokenRuleList Collections Based on their Type /// if they are invalid. /// </summary> public void AddBrokenRulesList(Type type, BrokenRulesList otherList) { //skip, no rules broken if (otherList == null || otherList.Count == 0) if (type == null) type = typeof(object); BrokenRulesLists.Add(type, otherList); }
/// <summary> /// Provides a method to aggregate BrokenRuleList Collections Based on their Type /// if they are invalid. /// </summary> public void AddBrokenRulesList(Type type, BrokenRulesList otherList) { //skip, no rules broken if (otherList == null || otherList.Count == 0) { if (type == null) { type = typeof(object); } } BrokenRulesLists.Add(type, otherList); }
/// <summary> /// Given a list /// containing IRuleMethod objects, this /// method executes all those rule methods. /// </summary> private void CheckRules(List <IRuleMethod> list) { bool previousRuleBroken = false; bool shortCircuited = false; for (int index = 0; index < list.Count; index++) { IRuleMethod rule = list[index]; // see if short-circuiting should kick in if (!shortCircuited && (previousRuleBroken && rule.Priority > _processThroughPriority)) { shortCircuited = true; } if (shortCircuited) { // we're short-circuited, so just remove // all remaining broken rule entries BrokenRulesList.Remove(rule); } else { // we're not short-circuited, so check rule if (rule.Invoke(_target)) { // the rule is not broken BrokenRulesList.Remove(rule); } else { // the rule is broken BrokenRulesList.Add(rule); if (rule.RuleArgs.Severity == RuleSeverity.Error) { previousRuleBroken = true; } } if (rule.RuleArgs.StopProcessing) { shortCircuited = true; } } } }
/// <summary> /// Invokes all rule methods for all properties /// in the object. /// </summary> public void CheckRules() { // get the rules for each rule name foreach (KeyValuePair <string, List <RuleMethod> > de in RulesList) { List <RuleMethod> list = de.Value; // now check the rules foreach (RuleMethod rule in list) { if (rule.Invoke()) { BrokenRulesList.Remove(rule); } else { BrokenRulesList.Add(rule); } } } }
public EntitySaveResult(BrokenRulesList brokenRules) : base(brokenRules) { }
public GenericDataSaveResult(BrokenRulesList brokenRules, T item) : base(brokenRules) { Item = item; }
public GenericDataSaveResult(BrokenRulesList brokenRules) : this(brokenRules, null) { }
public static QueryResult <T> Fail(BrokenRulesList brokenRules) => new QueryResult <T>(brokenRules);
public QueryResult(BrokenRulesList brokenRules) { Succeeded = brokenRules.Count == 0; BrokenRules = brokenRules ?? new BrokenRulesList(); Message = Succeeded ? "Success" : string.IsNullOrWhiteSpace(BrokenRules.Message) ? "Failed" : BrokenRules.Message; }
public static CommandResult Fail(BrokenRulesList brokenRules) => new CommandResult(brokenRules);