Xaml Configuration

ValidationAspects can be configured via xaml configuration. To use this, your application must reference the following assemblies and load the xaml configuration file.
  • PresentationCore
  • PresentationFramework
  • WindowsBase
Example:
using ValidationAspects.Configuration;
...
using (FileStream fileStream = File.OpenRead(configFileName))
{
	TypeValidation configuation = XamlReader.Load(fileStream) as TypeValidation;
	if (configuation != null)
		configuation.Configure();
}

<TypeValidation xmlns="clr-namespace:ValidationAspects.Configuration;assembly=ValidationAspects"
								xmlns:validators="clr-namespace:ValidationAspects.Factories;assembly=ValidationAspects"
								xmlns:domain="clr-namespace:Examples;assembly=Examples"
								Type="domain:Customer"
								Apply="Add">
	<TypeValidation.Validators>
		<domain:MyCustomerValidation />
	</TypeValidation.Validators>
	<TypeValidation.Properties>
		<PropertyValidation Property="Age" Apply="Replace">
			<PropertyValidation.Validators>
				<validators:LessThan Value="100" />
				<validators:Minimum Value="21" />
			</PropertyValidation.Validators>
		</PropertyValidation>
	</TypeValidation.Properties>
	<TypeValidation.Methods>
		<MethodValidation Method="Void SetEmail(System.String)" Apply="Add">
			<MethodValidation.Validators>
				<validators:ValidateObject />
			</MethodValidation.Validators>
			<MethodValidation.Parameters>
				<ParameterValidation Parameter="email" Apply="Add">
					<ParameterValidation.Validators>
						<validators:NotEqual Text="none" />
					</ParameterValidation.Validators>
				</ParameterValidation>
			</MethodValidation.Parameters>
		</MethodValidation>
	</TypeValidation.Methods>
</TypeValidation> 

When setting validation programmatically or by configuration, if a Validator is applied to an unsupported type, a ValidationException will be thrown immediately. This is so that the incorrect configuration fails fast and can be handled. This check is performed on-demand for generic parameter types.

Last edited Feb 3, 2009 at 6:38 PM by mikesaunders, version 6

Comments

No comments yet.