Details of How Validators are Created

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

The latest Enterprise Library information can be found at the Enterprise Library site.

When the application block creates a validator, it uses a set of requirements to determine which types and members of those types can be associated with that validator. (Members can be methods, properties, and fields.)

In general, when the application block creates a validator it evaluates the associated type and its members. Only members that have the following characteristics can be associated with a validator:

  • All members must be public members.
  • Methods must be non-void and take no parameters.
  • Properties must be readable.

Self validation has a different set of requirements. They are:

  • Self validation applies only to methods.
  • A self-validation method can be non-public.
  • The method signature must be void [method](ValidationResults).
  • Self validation can apply to inherited methods but not to methods that are private and inherited.

Creating Validators with Configuration

Configuration has the following characteristics:

  • Identifier collisions should not occur because names must be unique and the signatures for the methods are known beforehand.
  • It does not support self validation.

Creating Validators with Attributes

In general, attributes can have classes and members as targets. The requirements are:

  • Validators that apply to specific .NET Framework types, such as the Regular Expression Validator and the String Length Validator cannot be applied to classes.
  • The SelfValidation attribute only applies to methods.
  • The only cases where attributes can be applied to parameters is with WCF integration and with the Policy Injection Application Block.
Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

The latest Enterprise Library information can be found at the Enterprise Library site.