/// <summary> /// Set validation rule. /// </summary> public void SetValidationRule(IControlHabanero inputComponent, ValidationRule vr) { if (inputComponent != null) { // only throw error in DesignMode if (!this.CanExtend(inputComponent)) { throw new InvalidOperationException(inputComponent.GetType() + " is not supported by the validation provider."); } if (!this.IsDefaultRange(vr) && ValidationRule.Compare(vr.MinimumValue, vr.MaximumValue, ValidationCompareOperator.GreaterThanEqual, vr)) { throw new ArgumentException("MinimumValue must not be greater than or equal to MaximumValue."); } //ValidationRule vrOld = this._ValidationRules[inputComponent] as ValidationRule; // if new rule is valid and in not DesignMode, clone rule if ((vr != null)) { vr = vr.Clone() as ValidationRule; } if (!this._validationRules.ContainsKey(inputComponent)) { List <ValidationRule> vrList = new List <ValidationRule>(); vrList.Add(vr); this._validationRules.Add(inputComponent, vrList); } else if ((vr != null) && !this._validationRules[inputComponent].Contains(vr)) { this._validationRules[inputComponent].Add(vr); } } }
/// <summary> /// Set validation rule. /// </summary> public void SetValidationRule(IControlHabanero inputComponent, ValidationRule vr) { if (inputComponent != null) { // only throw error in DesignMode if (!this.CanExtend(inputComponent)) throw new InvalidOperationException(inputComponent.GetType() + " is not supported by the validation provider."); if (!this.IsDefaultRange(vr) && ValidationRule.Compare(vr.MinimumValue, vr.MaximumValue, ValidationCompareOperator.GreaterThanEqual, vr)) throw new ArgumentException("MinimumValue must not be greater than or equal to MaximumValue."); //ValidationRule vrOld = this._ValidationRules[inputComponent] as ValidationRule; // if new rule is valid and in not DesignMode, clone rule if ((vr != null) ) { vr = vr.Clone() as ValidationRule; } if(!this._validationRules.ContainsKey(inputComponent)) { List<ValidationRule> vrList = new List<ValidationRule>(); vrList.Add(vr); this._validationRules.Add(inputComponent,vrList); } else if ((vr != null) && !this._validationRules[inputComponent].Contains(vr)) { this._validationRules[inputComponent].Add(vr); } } }