Share via


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. Properties associated with the nodes appear in the right pane of the Configuration Console or the Properties window of the Visual Studio Configuration Editor.

The Validation Application Block allows you to use attributes and code to perform many of the tasks described here. For information about how to use attributes and code, see Using the Provided Validators. For information about 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. For details of the schema for the Validation Application Block configuration, see Source Schema for the Validation Application Block.

To add the Validation Application Block

  1. Open the configuration file. For more information, see Configuring Enterprise Library.
  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 then 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 have already added the Validation Application Block to your configuration.

To define a rule set for members of a type

Right-click Validation Application Block, point to New, and click Type.

In the Type Selector — System.Object dialog box, expand the assembly you want to use. If the assembly is not in the dialog box, click Load Assembly and navigate to it.

Double-click the type you want to validate.

(Optional) If there is an existing rule set you want to specify as the default, click DefaultRule in the properties pane and select it from the drop-down box.

To define a rule set, right-click on the type node, point to New, and then click Rule Set. Note that a rule set can contain as few as one validator.

Click in the Name property field and rename the rule set as required.

To select the member you want to validate, you can use either of the following methods:

  • Right-click RuleSet, point to New, and then click Field, Method, or Property. Then enter the name of the field, method, or property in the properties pane.
  • Alternatively, you can select various type members simultaneously. Right-click Rule Set, point to New, and then click Choose Members. In the Member Selector dialog box, select the Properties, Methods, and/or Fields that you want to validate, and then click OK.

Right-click the field, method, or property, point to New, and then click the validator you want to apply.

(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 button (...) and use the Type Selector — System.Object dialog box to select it.

Enter values for the remaining validator properties. The properties available differ for each type of validator. For a list of properties for each type of validator, see Using the Provided Validators.

Repeat steps 8 to 10 for each validator that you require for the selected member. All the validators you add for a specific member must evaluate to true for validation to succeed.

Repeat steps 7 to 10 for each member of the type that you want to validate.

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 6 of the procedure "To define a rule set for members of a type."
  2. Right-click Self, point to New, and then 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 require. All the validators you add for a specific type must evaluate to true for validation to succeed.

The next procedure explains how to define an AndCompositeValidator or an OrCompositeValidator composite validator. Composite validators contain individual validators that are combined with a Boolean AND or OR operation. You can nest them to create complex logic for a member, such as (A OR (B AND C)).

To define composite validators

  1. Repeat steps 1 to 6 of the procedure "To define a rule set for members of a type."
  2. Right-click the type member that you want to validate or the Self node, and then click either AndCompositeValidator or OrCompositeValidator.
  3. Right-click AndCompositeValidator or OrCompositeValidator, and then click one of the validators that will be a part of the composite validator.
  4. 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 the ellipsis button (…) 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.
  5. Repeat steps 3 and 4 for each validator that you require to create the logic for the current AndCompositeValidator or OrCompositeValidator.
  6. Repeat steps 2 to 5 for each AndCompositeValidator or OrCompositeValidator you require.