Q. Do I have to write a ValidationFactory/ValidationAttribute/ValidationException for every custom validator?
A. NO. One of ValidationAspects' main features is that you can write validation functions using lambda expressions and register them directly on the Type/PropertyInfo/MethodBase/ParameterInfo. See the Validation Functions section in Custom Validators. Create ValidationFactories for more general case validation that you would want to reuse. The Built-in Validators are examples of general usage Validation Factories. Use the InlineValidationFactory for a quick way to implement validation within a ValidationAttribute.

Q. How do I validate an object?
A. Simple - call object.Validate() on it and a ValidationResult will be returned. For more info see the Object Validation section in Declare Validation in Code. You need to be aware of Property Validation Modes to validate an object's properties.

Q. How can I identify what validation failed - where a ValidationException was thrown from?
A. Validation Exceptions have a Context member which provides the Type/Property/Method/Parameter/Arguments the failing validator is registered on. You may want to navigate the exception hierarchy which is explained here: Validation Exceptions

Q. How can I get the Property name to format an exception message?
A. Please see Exception Formatting for more info on this.

Q. What are the differences between State & Interception Validation and how does .net 4 Code Contracts compare?
A. Please see this blog post: http://thetreeknowseverything.net/2009/01/25/state-vs-interception-validation-vs-code-contracts/

Q. I don't want to use Interception Validation. Can I switch it off? Do I still need to be dependant on PostSharp?
A. Interception Validation can be disabled via the Property Validation Modes. If Interception Validation is disabled you will not be able to validate Methods and Method Parameters. AOP frameworks such as PostSharp and Unity are only required for Interception Validation.

Last edited Feb 3, 2009 at 4:35 PM by mikesaunders, version 4


No comments yet.