Retriving the list of validators

Jun 12, 2009 at 3:25 PM


I'm using VAB in a huge WPF project and everything is working fine, I would like to improve UX giving the user the ability to preview validation rules that will be applied.

Given a type and a ruleset I would like to know if there is a way to have a collection/list of validators (mixing Attributevalidators & configuration ones) that will be applied at the given type when validation occurs, we would like to use those informations to build a contextual help so to support the user during forms filling.


Jun 15, 2009 at 7:44 AM
Edited Jun 15, 2009 at 7:48 AM

This should work for those defined in configuration files.

  IConfigurationSource configSource = new SystemConfigurationSource();
            ValidationSettings settings = (ValidationSettings)configSource.GetSection("validation");
            ValidatedTypeReference typeReference = settings.Types.Get(typeof(Foo).FullName);
            foreach (ValidationRulesetData ruleSet in typeReference.Rulesets)
                var fields = ruleSet.Fields.ToList();
                foreach (var field in fields)
                     // access field.Validators property.


For the ones which are defined as attributes, I haven't tried it yet but that would require a lot of reflection I think.  You could examine the EntLib source code on how it creates validators from attributes (ValidationFactory.CreateValidatorFromAttributes).


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.

Jun 16, 2009 at 8:05 AM

Hi Sarah,

thank you very much for the suggestion, I'll give it a try and let you know.