Exemplo n.º 1
0
        public bool Validate()
        {
            bool   isValid      = true;
            string errorMessage = "";

            foreach (IValidator validator in Validators)
            {
                bool result = validator.Check(_view.GetType()
                                              .GetProperty(PropertyName)
                                              .GetValue(_view) as string);
                isValid = isValid && result;

                if (!result)
                {
                    errorMessage = validator.Message;
                    break;
                }
            }

            if (!isValid)
            {
                _style.ShowError(_view, errorMessage);

                return(false);
            }
            else
            {
                _style.RemoveError(_view);

                return(true);
            }
        }
Exemplo n.º 2
0
        public bool Validate()
        {
            bool   isValid      = true;
            string errorMessage = "";

            foreach (IValidator validator in Validators)
            {
                bool result;
                var  isPicker = (_view as Picker);
                if (isPicker != null)
                {
                    if (isPicker.SelectedIndex == -1)
                    {
                        result = false;
                    }
                    else
                    {
                        result = true;
                    }
                }
                else
                {
                    var value = _view.GetType()
                                .GetProperty(PropertyName)
                                .GetValue(_view) as string;
                    result = validator.Check(value);
                }
                isValid = isValid && result;

                if (!result)
                {
                    errorMessage = validator.Message;
                    break;
                }
            }
            if (!isValid)
            {
                _style.ShowError(_view, errorMessage);

                return(false);
            }
            else
            {
                _style.RemoveError(_view);

                return(true);
            }
        }