public void AddValidator(PropertyGridValidator validator) { Debug.Assert(validator != null, "validator 为 null"); Debug.Assert(_validatorCollection.Contains(validator) == false, "已经添加过了指定的 wrapper"); if (validator == null || _validatorCollection.Contains(validator)) { return; } _validatorCollection.Add(validator); }
/// <summary> /// 请求验证单元格中欲设置的属性(Property)值 /// 此方法提供给编辑单元格调用,只有这样才能在验证失败时阻止值设置到属性行中 /// </summary> /// <param name="property"></param> /// <param name="value"></param> /// <param name="changed"></param> /// <returns></returns> public PropertyGridValidateResult ValidateValue(string property, object value, bool changed) { if (changed == false) { return(new PropertyGridValidateResult()); } PropertyGridValidator validator = _validatorCollection.GetValidator(this.SelectedObjects); if (validator == null) { return(new PropertyGridValidateResult()); } if (validator.Validator == null) { Debug.Assert(false, "validator.Validator 为空"); return(new PropertyGridValidateResult()); } PropertyGridValidateArgs argss = new PropertyGridValidateArgs(property, value, this.SelectedObjects); return(validator.Validator(argss)); }