Retriving the list of validators

Jun 12, 2009 at 2:25 PM

Hi,

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.

TIA,
Mauro

Jun 15, 2009 at 6:44 AM
Edited Jun 15, 2009 at 6: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.
entlib.support@avanade.com

        
Jun 16, 2009 at 7:05 AM

Hi Sarah,

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

.m