Ejemplo n.º 1
0
        public static void AddRequiredValidator <TReturnType>(this ValidatableViewModelBase validatableViewModel,
                                                              Expression <Func <TReturnType> > expression, string validateErrorMessage = null)
        {
            string propertyName = expression.GetMemberName();

            ((IValidate)validatableViewModel.Validator).Register <TReturnType>(propertyName, i =>
            {
                if (i is null)
                {
                    return(ValidateResult.Invalid);
                }

                return(ValidateResult.Valid);
            }, validateErrorMessage ?? $"{propertyName} is NULL");
        }
Ejemplo n.º 2
0
        public static void AddMinLengthValidator(this ValidatableViewModelBase validatableViewModel,
                                                 Expression <Func <string> > expression, int minLength, string validateErrorMessage = null)
        {
            string propertyName = expression.GetMemberName();

            ((IValidate)validatableViewModel.Validator).Register <string>(propertyName, i =>
            {
                if (i is null)
                {
                    return(ValidateResult.Invalid);
                }

                if (i.Length < minLength)
                {
                    return(ValidateResult.Invalid);
                }

                return(ValidateResult.Valid);
            },
                                                                          validateErrorMessage ?? $"{propertyName} MinLength is {minLength}");
        }
Ejemplo n.º 3
0
 internal Validator(ValidatableViewModelBase validateOwner)
 {
     _owner     = validateOwner;
     _ownerType = validateOwner.GetType();
 }