public PropertyControl(FrameworkElement control, string displayName, IValidRule validRule, string propertyName) { Control = control; DisplayName = displayName; ValidRule = validRule; PropertyName = propertyName; }
/// <summary> /// 增加验证规则 /// </summary> /// <param name="rule">验证规则</param> private void AddRule(IValidRule rule) { this.ValidRules = this .ValidRules .Concat(new[] { rule }) .OrderBy(item => item.OrderIndex) .ToArray(); }
/// <summary> /// 表示一般验证框对象 /// <param name="validRule">后台验证规则</param> /// <param name="validType">验证类型</param> /// <param name="validMessage">不通过时提示信息</param> /// <param name="parameters">验证的参数</param> /// </summary> public static ValidBox New(IValidRule validRule, string validType, string validMessage, params object[] parameters) { var box = new ValidBox(); var rule = ValidBox.GenerateRule(validType, validMessage, parameters); box.validRuleList.Add(validRule); box.ruleList.Add(rule); return(box); }
/// <summary> /// 表示必须输入的验证框对象 /// </summary> /// <param name="validRule">后台验证规则</param> /// <param name="requiredMessage">未输入时的提示信息</param> public static ValidBox Request(IValidRule validRule, string requiredMessage) { var box = new ValidBox { required = true, requiredMessage = requiredMessage }; box.validRuleList.Add(validRule); return(box); }
/// <summary> /// 替换验证规则 /// </summary> /// <param name="rule">验证规则</param> /// <returns></returns> private bool Replace(IValidRule rule) { for (var i = 0; i < this.ValidRules.Length; i++) { if (this.ValidRules[i].GetType() == rule.GetType()) { this.ValidRules[i] = rule; return(true); } } return(false); }
/// <summary> /// 增加或更新规则 /// </summary> /// <param name="rule">验证规则</param> /// <exception cref="ArgumentNullException"></exception> public void SetRule(IValidRule rule) { if (rule == null) { throw new ArgumentNullException(); } if (this.Replace(rule) == false) { this.AddRule(rule); } }
/// <summary> /// 增加或替换验证规则到类型的属性 /// </summary> /// <typeparam name="TKey">键类型</typeparam> /// <param name="keySelector">属性选择</param> /// <param name="rule">验证规则</param> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="ArgumentException"></exception> /// <exception cref="NotSupportedException"></exception> /// <returns></returns> public FluentApi <T> SetRule <TKey>(Expression <Func <T, TKey> > keySelector, IValidRule rule) { FluentApiExtend.GetProperty(keySelector).SetRule(rule); return(this); }
/// <summary> /// 替换验证规则 /// </summary> /// <param name="rule">验证规则</param> /// <returns></returns> private bool Replace(IValidRule rule) { for (var i = 0; i < this.ValidRules.Length; i++) { if (this.ValidRules[i].GetType() == rule.GetType()) { this.ValidRules[i] = rule; return true; } } return false; }
/// <summary> /// 表示必须输入的验证框对象 /// </summary> /// <param name="validRule">后台验证规则</param> /// <param name="requiredMessage">未输入时的提示信息</param> public static ValidBox Request(IValidRule validRule, string requiredMessage) { var box = new ValidBox { required = true, requiredMessage = requiredMessage }; box.validRuleList.Add(validRule); return box; }
/// <summary> /// 表示一般验证框对象 /// <param name="validRule">后台验证规则</param> /// <param name="validType">验证类型</param> /// <param name="validMessage">不通过时提示信息</param> /// <param name="parameters">验证的参数</param> /// </summary> public static ValidBox New(IValidRule validRule, string validType, string validMessage, params object[] parameters) { var box = new ValidBox(); var rule = ValidBox.GenerateRule(validType, validMessage, parameters); box.validRuleList.Add(validRule); box.ruleList.Add(rule); return box; }
public PropertyBuilder(string propName, string displayName, IValidRule rule) { this.propName = propName; this.displayName = displayName; this.rule = rule; }