Entering Configuration Information

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.

These procedures explain how to configure the Validation Application Block with the configuration tools.

The Validation Application Block differs from other application blocks in that you can use attributes and code to perform many of the tasks described here. For information on how to use attributes and code, see Using the Provided Validators. For information on properties that are associated with validators such as Tag and MessageTemplate, see Understanding Common Validator Properties.

This procedure explains how to add the Validation Application Block to the configuration file.

To Add the Validation Application Block

  1. Open the configuration file. For more information, see Configuring the Application Blocks
  2. Right-click Application Configuration, point to New, and then click Validation Application Block.
  3. (Optional) If you want to encrypt the configuration file, click in the ProtectionProvider field and select a protection provider from the drop-down list.

The next procedure shows how to define a rule set for the members of a type. Members of a type can be fields, methods, or properties. Note that it is possible for a type to have multiple rule sets associated with it. The procedure assumes that you already added the Validation Application Block.

To define a rule set for members of a type

  1. Right-click on Validation Application Block, point to New, and click Type.
  2. The Type Selector — System.Object dialog box opens.
  3. Expand the assembly you want to use. If the assembly is not in the dialog box, click Load Assembly and navigate to it.
  4. Double-click on the type you want to validate.
  5. (Optional) If there is an existing rule set you want to specify as the default, click on DefaultRule in the right pane and select it from the dropdown box.
  6. To define a rule set right-click on the type node, point to New, and click RuleSet. Note that a rule set can contain as few as one validator.
  7. (Optional) Click in the Name property field and rename the rule set.
  8. To select what you want to validate, right-click on RuleSet, point to New, and select Field, Method, or Property.
  9. (Optional) Enter the name of the field, method, or property in the right pane.
  10. (Alternative) As an alternative to steps 7 and 8, you can select various type members simultaneously. Right-click on Rule Set, point to New, and select Choose Members. The Member Selector dialog box appears. Select the Properties, Methods, and/or Fields that you want to validate. Click OK.
  11. Right-click on the field, method or property, point to New and select the validator you want to apply.
  12. (Optional) Fill in the Tag, MessageTemplate, and MessageTemplateResource fields, as appropriate. If you use the MessageTemplateResource property you must also specify the MessageTemplateResourceTypeName property. You can either enter the name of the MessageTemplateResourceTypeName type in the field or click on the ellipsis and use the Type Selector — System.Object dialog box to select it. Many validators also have fields that are specific to them. Fill these out as well.
  13. Repeat steps 11 and 12 for each validator that you add.

The next procedure shows how to apply validators at the type level. A type-level validator applies to an instance of a class as a whole rather than to members of that class. Typically, you will use a custom validator that you have created yourself although the Not Null Validator may also be appropriate.

To apply validators at the type level

  1. Repeat steps 1 through 7 of the To define a rule set for members of a type procedure.
  2. Right-click on Self, point to New, and click the validator you want to use. Typically this is either Custom Validator or Not Null Validator.
  3. For each validator, fill in the Tag, MessageTemplate and MessageTemplateResource fields, as appropriate. If you use the MessageTemplateResource property you must also specify the MessageTemplateResourceTypeName property. You can either enter the MessageTemplateResourceTypeName type in the field or click on the ellipsis and use the Type Selector — System.Object dialog box to select it. Many validators also have fields that are specific to them. Fill these out as well.
  4. Repeat steps 2 and 3 for each validator that you add.

The next procedure explains how to define composite validators. Composite validators are built from individual validators that are combined with a Boolean AND or OR. If you supply multiple validators for the same member type, they are implicitly combined with a Boolean AND operation. You need an AndCompositeValidator and an OrCompositeValidator if you want perform complex logic on a member such as (A OR (B AND C)).

To define composite validators

  1. Repeat steps 1 through 7 of the To define a rule set for members of a type procedure.
  2. Right-click on the type member that you want to validate or on the Self node.
  3. Select either AndCompositeValidator or OrCompositeValidator.
  4. Right-click on AndCompositeValidator or on OrCompositeValidator and select one of the validators that will be a part of the composite validator.
  5. For each validator, fill in the Tag, MessageTemplate and MessageTemplateResource fields, as appropriate. If you use the MessageTemplateResource property you must also specify the MessageTemplateResourceTypeName property. You can either enter the MessageTemplateResourceTypeName type in the field or click on the ellipsis and use the Type Selector — System.Object dialog box to select it. Many validators also have fields that are specific to them. Fill these out as well.
  6. Repeat steps 4 and 5 for each validator that you add.

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.
Show: