コード例 #1
0
        /// <summary>
        /// 通过校验定义Schema, 执行校验
        /// </summary>
        /// <param name="validationSchema"></param>
        /// <param name="value"></param>
        /// <param name="errHint"></param>
        /// <returns></returns>
        public static bool InvokeValid(ValidationSchema validationSchema, string value, CheckVarHandle checkHandl, out string errHint)
        {
            List <ValidationItemSchema> items = validationSchema.Validators;



            for (int i = 0; i < items.Count; i++)
            {
                ValidationItemSchema          item    = items[i];
                IdsObjectList <IdValueObject> options = new IdsObjectList <IdValueObject>();
                for (int j = 0; j < item.Options.Count; j++)
                {
                    IdValueObject op    = item.Options[j];
                    IdValueObject newOp = new IdValueObject();
                    newOp.Id    = op.Id;
                    newOp.Value = op.Value;
                    if (checkHandl != null)
                    {
                        newOp.Value = checkHandl(newOp.Value).ToString();
                    }
                    options.Add(newOp);
                }



                Validator validator = GetValidator(item.ValidatorName);

                ActionUtils.SetObjProperties(validator, options);
                errHint = validator.ErrHint;
                if (!validator.Check(value))
                {
                    return(false);
                }
            }

            errHint = "";
            return(true);
        }