/// <summary> /// Invokes all rule methods associated with /// the specified property and any /// dependant properties. /// </summary> /// <param name="propertyName">The name of the property to validate.</param> public void CheckRules(string propertyName) { // get the rules dictionary ValidationRulesManager rules = RulesToCheck; if (rules != null) { // get the rules list for this property RulesList rulesList = rules.GetRulesForProperty(propertyName, false); if (rulesList != null) { // get the actual list of rules (sorted by priority) List <IRuleMethod> list = rulesList.GetList(true); if (list != null) { CheckRules(list); } List <string> dependancies = rulesList.GetDependancyList(false); if (dependancies != null) { for (int i = 0; i < dependancies.Count; i++) { string dependantProperty = dependancies[i]; CheckRules(rules, dependantProperty); } } } } }
private ValidationRulesManager GetTypeRules(bool createObject) { if (_typeRules == null) { _typeRules = SharedValidationRules.GetManager(_target.GetType(), createObject); } return(_typeRules); }
/// <summary> /// Adds a property to the list of dependencies for /// the specified property /// </summary> /// <param name="propertyName"> /// The name of the property. /// </param> /// <param name="dependantPropertyName"> /// The name of the depandent property. /// </param> /// <param name="isBidirectional"> /// If <see langword="true"/> then a /// reverse dependancy is also established /// from dependantPropertyName to propertyName. /// </param> /// <remarks> /// When rules are checked for propertyName, they will /// also be checked for any dependant properties associated /// with that property. If isBidirectional is /// <see langword="true"/> then an additional association /// is set up so when rules are checked for /// dependantPropertyName the rules for propertyName /// will also be checked. /// </remarks> public void AddDependantProperty(string propertyName, string dependantPropertyName, bool isBidirectional) { ValidationRulesManager mgr = GetTypeRules(true); mgr.AddDependantProperty(propertyName, dependantPropertyName); if (isBidirectional) { mgr.AddDependantProperty(dependantPropertyName, propertyName); } }
private ValidationRulesManager GetInstanceRules(bool createObject) { if (_instanceRules == null) { if (createObject) { _instanceRules = new ValidationRulesManager(); } } return(_instanceRules); }
/// <summary> /// Invokes all rule methods for all properties /// in the object. /// </summary> public void CheckRules() { ValidationRulesManager rules = RulesToCheck; if (rules != null) { foreach (KeyValuePair <string, RulesList> de in rules.RulesDictionary) { CheckRules(de.Value.GetList(true)); } } }
/// <summary> /// Gets the <see cref="ValidationRulesManager"/> for the /// specified object type, optionally creating a new instance /// of the object if necessary. /// </summary> /// <param name="objectType"> /// Type of business object for which the rules apply. /// </param> /// <param name="create">Indicates whether to create /// a new instance of the object if one doesn't exist.</param> internal static ValidationRulesManager GetManager(Type objectType, bool create) { ValidationRulesManager result = null; if (!_managers.TryGetValue(objectType, out result) && create) { lock (_managers) { result = new ValidationRulesManager(); _managers.Add(objectType, result); } } return(result); }
private void CheckRules(ValidationRulesManager rules, string propertyName) { // get the rules list for this property RulesList rulesList = rules.GetRulesForProperty(propertyName, false); if (rulesList != null) { // get the actual list of rules (sorted by priority) List <IRuleMethod> list = rulesList.GetList(true); if (list != null) { CheckRules(list); } } }
/// <summary> /// Returns an array containing the text descriptions of all /// validation rules associated with this object. /// </summary> /// <returns>String array.</returns> /// <remarks></remarks> public string[] GetRuleDescriptions() { List <string> result = new List <string>(); ValidationRulesManager rules = RulesToCheck; if (rules != null) { foreach (KeyValuePair <string, RulesList> de in rules.RulesDictionary) { List <IRuleMethod> list = de.Value.GetList(false); for (int i = 0; i < list.Count; i++) { IRuleMethod rule = list[i]; result.Add(rule.ToString()); } } } return(result.ToArray()); }