Ejemplo n.º 1
0
        public static string ValidateAge(ViewModelWithErrorInfo vm, int age)
        {
            if (age <= 0)
            {
                return("Age must be positive");
            }

            return(null);
        }
Ejemplo n.º 2
0
        public static IDisposable SetupValidation <TProperty>(this ViewModelWithErrorInfo vm, Expression <Func <ViewModelWithErrorInfo, TProperty> > expr,
                                                              Func <ViewModelWithErrorInfo, TProperty, string> validateFunc)
        {
            var name                  = expr.GetMember();
            var errorInfoType         = typeof(IPropertyErrorsContainer <>).MakeGenericType(vm.GetType());
            var setupValidationMethod = errorInfoType.GetMethod("SetupValidation").MakeGenericMethod(typeof(TProperty));
            var result                = (IDisposable)setupValidationMethod.Invoke(vm.ErrorInfo, new object[] { name, validateFunc });

            return(result);
        }
Ejemplo n.º 3
0
        public static string ValidateName(ViewModelWithErrorInfo vm, string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                return("Name cannot be empty.");
            }

            if (name?.Length <= 5)
            {
                return("Name must be at least 6 characters long.");
            }

            return(null);
        }
Ejemplo n.º 4
0
 public static IDisposable SetupNameValidation(this ViewModelWithErrorInfo vm)
 {
     return(vm.SetupValidation <ViewModelWithErrorInfo, string>(vm.ErrorInfo, o => o.Name, ValidateName));
 }
Ejemplo n.º 5
0
 public static void ClearValidations(this ViewModelWithErrorInfo vm)
 {
     vm.ErrorInfo.ClearValidations();
 }
Ejemplo n.º 6
0
 public static IDisposable SetupAgeValidation(this ViewModelWithErrorInfo vm)
 {
     return(vm.SetupValidation <ViewModelWithErrorInfo, int>(vm.ErrorInfo, o => o.Age, ValidateAge));
 }