コード例 #1
0
        public IValidationResult CheckForLength(object obj, int minLenght, int maxLength, string propName)
        {
            if (msStringLengthValidator == null)
            {
                msStringLengthValidator = new StringLengthValidator(minLenght, maxLength);
            }
            else if (msStringLengthValidator.LowerBound != minLenght ||
                     msStringLengthValidator.UpperBound != msStringLengthValidator.UpperBound)
            {
                msStringLengthValidator = new StringLengthValidator(minLenght, maxLength);
            }

            ValidationResults valResults = msStringLengthValidator.Validate(obj);

            if (valResults != null)
            {
                if (ValidationResult == null)
                {
                    ValidationResult = new MyValidationResult();
                }

                foreach (var varRes in valResults)
                {
                    IValidationMessage val = new MSWrapperMessage(MessageTypes.Error, varRes.Message)
                    {
                        TargetName = propName, ErroringValue = obj.ToString()
                    };
                    ValidationResult.ValidationMessageList.Add(val);
                }
            }

            return(ValidationResult);
        }
コード例 #2
0
        public IValidationResult CheckForNotNull(object obj, string propName)
        {
            if (MSNotNullValidator == null)
            {
                MSNotNullValidator = new NotNullValidator();
            }

            ValidationResults valResults = MSNotNullValidator.Validate(obj);

            if (valResults != null)
            {
                if (ValidationResult == null)
                {
                    ValidationResult = new MyValidationResult();
                }

                foreach (var varRes in valResults)
                {
                    IValidationMessage val = new MSWrapperMessage(MessageTypes.Error, varRes.Message)
                    {
                        TargetName = propName
                    };
                    ValidationResult.ValidationMessageList.Add(val);
                }
            }
            return(ValidationResult);
        }
コード例 #3
0
        public IValidationResult Validate()
        {
            if (!IsOverriden)
            {
                //MS Validation
                Validator NotNullStringLengthValidator = new AndCompositeValidator(this.msNotNullValidator, this.msStringLengthValidator);

                ValidationResults valResults = NotNullStringLengthValidator.Validate(Customer.customerNumber);

                if (!valResults.IsValid) //if not valid
                {
                    RuleValidationResult = new MyValidationResult();
                    RuleValidationResult.ValidationMessageList.Add(new NullValidationMessage());
                }


                if (Customer.EmailList != null)
                {
                    //Some other Random Test Validation. RegexValidator in this case
                    Validator <string> emailAddresssValidator = new RegexValidator(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
                    valResults = emailAddresssValidator.Validate(Customer.EmailList.First());
                }
                else
                {
                    valResults = this.msNotNullValidator.Validate(Customer.EmailList);
                }

                //Holidays Own Validation

                //RuleValidationResult = valResults;

                if (valResults != null)
                {
                    RuleValidationResult = new MyValidationResult();

                    foreach (var varRes in valResults)
                    {
                        IValidationMessage val = new MSWrapperMessage(MessageTypes.Error, varRes.Message);
                        RuleValidationResult.ValidationMessageList.Add(val);
                    }
                }
            }

            return(RuleValidationResult);
        }