コード例 #1
0
        public OverallValidationResult Validate(Beer beer)
        {
            var context = new ValidationContext <Beer>(beer);

            context.RootContextData["BadBeers"] = new List <string> {
                BadBeer1, BadBeer2
            };

            // totally trivial example of cutting out the rule for "Manufacturer" on the Beer class, since we aren't capturing it here.
            // note if we didn't cut this out, then that rule would fail for our class instance and would be captured in the OverallValidationResult's NonSplitErrors list.
            var scopedRules = _beerValidator.GetRulesFor(_beerValidatables);

            var fluentValidationResult = new ValidationResult(scopedRules.SelectMany(x => x.Validate(context)).ToList());

            return(fluentValidationResult.ApplyResultsTo(_beerValidatables));
        }