Beispiel #1
0
        /// <summary>
        /// 获取属性的ValidBox
        /// </summary>
        /// <param name="property">属性</param>
        /// <param name="message">初始化提示消息</param>
        /// <returns></returns>
        private static ValidBox GetPropertyValidBox(PropertyInfo property, string message)
        {
            var validBox = ValidBox.Empty(message);

            // 值类型非空检测
            if (property.PropertyType.IsValueType && Attribute.IsDefined(property, typeof(RequiredAttribute)) == false)
            {
                validBox = ValidBox.Request(null);
            }

            var boxs = Attribute.GetCustomAttributes(property, false)
                       .Where(item => item is IValidRule)
                       .Cast <IValidRule>()
                       .OrderBy(item => item.OrderIndex)
                       .Select(item => item.ToValidBox());

            foreach (var box in boxs)
            {
                validBox = ValidBox.Merge(validBox, box);
            }

            // 数字类型输入检测
            if (property.PropertyType.IsNumberType() == true)
            {
                validBox = ValidBox.Merge(validBox, ValidBox.New("number", null));
            }
            return(validBox);
        }
 /// <summary>
 /// 转换为对应的ValidBox类型
 /// </summary>
 /// <returns></returns>
 public override ValidBox ToValidBox()
 {
     return(ValidBox.New(this.ValidType, this.ErrorMessage, this.TargetId));
 }
Beispiel #3
0
 /// <summary>
 /// 生成验证框对象
 /// </summary>
 /// <returns></returns>
 public ValidBox ToValidBox()
 {
     return(ValidBox.New("length", this.ErrorMessage, this.MinimumLength, this.MaximumLength));
 }
Beispiel #4
0
 /// <summary>
 /// 生成验证框对象
 /// </summary>
 /// <returns></returns>
 public override ValidBox ToValidBox()
 {
     return(ValidBox.New(this, this.ValidType, this.ErrorMessage, this.Length));
 }
Beispiel #5
0
 /// <summary>
 /// 转换为对应的ValidBox类型
 /// </summary>
 /// <returns></returns>
 public override ValidBox ToValidBox()
 {
     return(ValidBox.New(this.ValidType, this.ErrorMessage, this.RegexPattern));
 }
Beispiel #6
0
 /// <summary>
 /// 生成验证框对象
 /// </summary>
 /// <returns></returns>
 public override ValidBox ToValidBox()
 {
     return(ValidBox.New(this.ValidType, this.ErrorMessage, this.MinValue, this.MaxValue));
 }
Beispiel #7
0
        /// <summary>
        /// 验证输入是否为数字类型
        /// </summary>
        /// <param name="box">验证框</param>
        /// <param name="errorMessage">错误提示消息</param>
        /// <returns></returns>
        public static ValidBox Number(this ValidBox box, string errorMessage)
        {
            var newBox = ValidBox.New("number", errorMessage);

            return(ValidBox.Merge(box, newBox));
        }
Beispiel #8
0
        /// <summary>
        /// 验证输入是否为数字类型
        /// </summary>
        /// <param name="box">验证框</param>
        /// <returns></returns>
        public static ValidBox Number(this ValidBox box)
        {
            var newBox = ValidBox.New("number", null);

            return(ValidBox.Merge(box, newBox));
        }
Beispiel #9
0
        /// <summary>
        /// 生成验证框
        /// </summary>
        /// <returns></returns>
        public override ValidBox ToValidBox()
        {
            var parameters = new object[] { this.Url }.Concat(this.TargetId).ToArray();

            return(ValidBox.New(this, this.ValidType, this.ErrorMessage, parameters));
        }
Beispiel #10
0
 /// <summary>
 /// 转换为ValidBox
 /// </summary>
 /// <returns></returns>
 public override ValidBox ToValidBox()
 {
     this.ErrorMessage = "请输入正确的数值";
     return(ValidBox.New(this, this.ValidType, this.ErrorMessage));
 }