Example #1
0
        protected ValidatorResponse IsValid <T>(object validatorUnit, object validateValue, string typeName) where T : IComparable
        {
            ValidatorResponse response = new ValidatorResponse();
            bool ret = false;
            BaseValidateMessage message = null;
            Type type = typeof(T);

            if (type == typeof(string))
            {
                BaseValidatorUnit <string> validator = validatorUnit as BaseValidatorUnit <string>;
                ret     = validator.IsValid(validateValue.ToString());
                message = validator.validateMessage;
            }
            else
            {
                BaseValidatorUnit <T> validator = validatorUnit as BaseValidatorUnit <T>;
                T cnvertedValue = Core.Object.Convert.ToGenerics <T>(validateValue);
                ret     = validator.IsValid(cnvertedValue);
                message = validator.validateMessage;
            }
            if (false != ret)
            {
                message = new SuccessValidateMessage();
            }
            ValidatorResponseEntity entity = new ValidatorResponseEntity();

            entity.result  = ret;
            entity.message = message;
            response.responseList.Add(entity);
            return(response);
        }
Example #2
0
        public override ValidatorResponse IsValid(object validateValue, Dictionary <string, object> validatorList)
        {
            ValidatorResponse response = new ValidatorResponse();

            foreach (string typeName in validatorList.Keys)
            {
                object validatorUnit = validatorList[typeName];
                if (typeName.Equals("int"))
                {
                    response = this.IsValid <int>(validatorUnit, validateValue, typeName);
                }
                else if (typeName.Equals("long"))
                {
                    response = this.IsValid <long>(validatorUnit, validateValue, typeName);
                }
                else if (typeName.Equals("float"))
                {
                    response = this.IsValid <float>(validatorUnit, validateValue, typeName);
                }
                else if (typeName.Equals("double"))
                {
                    response = this.IsValid <double>(validatorUnit, validateValue, typeName);
                }
                else if (typeName.Equals("string"))
                {
                    BaseValidatorUnit <int> validator = validatorUnit as BaseValidatorUnit <int>;
                    bool ret = validator.IsValid(validateValue.ToString().Length);
                    BaseValidateMessage message = null;
                    if (!ret)
                    {
                        message = validator.validateMessage;
                    }
                    else
                    {
                        message = new SuccessValidateMessage();
                    }
                    ValidatorResponseEntity entity = new ValidatorResponseEntity();
                    entity.result  = ret;
                    entity.message = message;
                    response.responseList.Add(entity);
                }
                if (this.compareOption == CompareOption.Or)
                {
                    response.responseList.Clear();
                    break;
                }
            }
            return(response);
        }
        public override ValidatorResponse IsValid(object validateValue, Dictionary <string, object> validatorList)
        {
            ValidatorResponse response = new ValidatorResponse();

            foreach (string typeName in validatorList.Keys)
            {
                object validatorUnit = validatorList[typeName];
                BaseValidatorUnit <string> validator = validatorUnit as RegexValidatorUnit;
                bool ret = validator.IsValid(validateValue.ToString());
                ValidatorResponseEntity entity = new ValidatorResponseEntity();
                entity.result = ret;
                if (!ret)
                {
                    if (this.compareOption == CompareOption.Or)
                    {
                        if (0 == response.responseList.Count)
                        {
                            entity.message = validator.validateMessage;
                            response.responseList.Add(entity);
                        }
                    }
                    else
                    {
                        entity.message = validator.validateMessage;
                        response.responseList.Add(entity);
                    }
                }
                else
                {
                    if (this.compareOption == CompareOption.Or)
                    {
                        response.responseList.Clear();
                        break;
                    }
                }
            }
            return(response);
        }