Validating Objects

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.

Once you have the validators and rule sets, you can validate your objects. The easiest way to do this is to use the Validation façade. The façade allows you to you to create a Validator instance and validate an object with a single line of code. This is shown in the following code example. For more information see Details of Validating Objects in Details of Development Tasks.

Customer customer = new Customer();
ValidationResults results = Validation.Validate<Customer>(customer, customerRuleSetCombo.Text);
'Usage
Dim customer As Customer = CreateCustomer()
Dim results As ValidationResults = Validation.Validate(customer, _
customerRuleSetCombo.Text)

If you do not want to use the façade, you can use the following code, which is the equivalent.

Customer customer = new Customer();
Validator<Customer> validator = ValidationFactory.CreateValidator<Customer>(customerRuleSetCombo.Text);
ValidationResults results = validator.Validate(customer);
'Usage
Dim customer As Customer = CreateCustomer()
Dim validator As Validator(Of Customer) = ValidationFactory.CreateValidator(Of Customer)(customerRuleSetCombo.Text)
Dim results As ValidationResults = validator.Validate(customer)

Use the CreateValidator method on the ValidationFactory class to first get a reference to the Validator instance and then use the Validate method to validate the object.

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.