User220959680 posted
MSDN http://msdn.microsoft.com/en-us/library/dd140088.aspx. I copied the below from MSDN
You can also group validators together in a rule set. A rule set allows you to validate a complex object or graph by composing different validators of different types and applying them to elements in the object graph. Examples of these elements include fields,
properties, and nested objects.
By using the Validation Application Block, you can perform validation and create rule sets in the following three ways:
- Using configuration
- Using attributes
- Using code
private void acceptButton_Click(object sender, EventArgs e)
{
Customer customer = new Customer
{
FirstName = firstNameTextBox.Text,
LastName = lastNameTextBox.Text,
SSN = ssnTextBox.Text,
Address = new Address
{
StreetAddress = streetAddressTextBox.Text,
City = cityTextBox.Text,
State = stateComboBox.Text,
ZipCode = zipCodeTextBox.Text
}
};
ValidationResults results =
this.alternativeValidation.Checked
? Validation.Validate(customer, "Alternative")
: Validation.Validate(customer);
if (!results.IsValid)
{
StringBuilder builder = new StringBuilder();
builder.AppendLine("Customer is not valid:");
foreach (ValidationResult result in results)
{
builder.AppendLine(
string.Format(
CultureInfo.CurrentCulture,
"{0}: {1}",
result.Key,
result.Message));
}
MessageBox.Show(
this,
builder.ToString(),
"Error",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
return;
}
MessageBox.Show(
this,
"Processing customer '" + customer.FirstName + "'",
"Working",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
}