static void UsingDataAnnotationsValidationAttributesAndSelfValidation() { // Create and populate a product instance with invalid values. IProduct invalidProduct = new AnnotatedProduct(); PopulateInvalidProduct(invalidProduct); Console.WriteLine("Created and populated an invalid instance of the AnnotatedProduct class."); // Create a validator for this type. Can use the interface type or the actual product type. Validator <AnnotatedProduct> productValidator = ValidationFactory.CreateValidator <AnnotatedProduct>(); // Validate the instance to obtain a collection of validation errors. ValidationResults results = productValidator.Validate(invalidProduct); // Display the contents of the validation errors collection. ShowValidationResults(results); }
static void UsingDataAnnotationsValidationAttributesAndSelfValidation() { // Create and populate a product instance with invalid values. IProduct invalidProduct = new AnnotatedProduct(); PopulateInvalidProduct(invalidProduct); Console.WriteLine("Created and populated a valid instance of the AnnotatedProduct class."); // Create a validator for this type. Can use the interface type or the actual product type. Validator<AnnotatedProduct> productValidator = valFactory.CreateValidator<AnnotatedProduct>(); // Validate the instance to obtain a collection of validation errors. ValidationResults results = productValidator.Validate(invalidProduct); // Display the contents of the validation errors collection. ShowValidationResults(results); }