private IValidatorBuilder SetupValidatorBuilder(IValidatorBuilder builder)
 {
     return(builder
            .WithViewModel(_viewModel)
            .WithResultsPresenter((name, errors) => _presentedErrors.Add(name, errors.ToList()))
            .AddProperty(nameof(TestViewModel.FirstName))
            .AddProperty(nameof(TestViewModel.Password))
            .AddProperty(nameof(TestViewModel.RepeatPassword))
            .AddProperty(nameof(TestViewModel.Email)));
 }
Esempio n. 2
0
        /// <summary>
        /// Sets the view-model and registers all its public properties that have at least one <see cref="ValidationAttribute"/> applied.
        /// </summary>
        /// <param name="validatorBuilder">The <see cref="IValidatorBuilder"/> to add to.</param>
        /// <param name="viewModel">The view-model, which type will be selected</param>
        /// <returns>The original builder object</returns>
        /// <remarks>This method changes and returns the original builder object</remarks>
        public static IValidatorBuilder WithViewModelAndAllProperties(this IValidatorBuilder validatorBuilder, object viewModel)
        {
            validatorBuilder.WithViewModel(viewModel);
            foreach (var property in viewModel.GetType()
                     .GetProperties()
                     .Where(property => property
                            .GetCustomAttributes <ValidationAttribute>()
                            .Any()))
            {
                validatorBuilder.AddProperty(property.Name);
            }

            return(validatorBuilder);
        }