I have a bunch of data classes in my C# project. I need to perform a validation before the processing of the objects of those classes. The classes donot have a common interface.
I am trying to formulate some sort of design pattern where I can specify the validations that need to be performed on each field of the class; without having a set of if else type conditions.
I came across the specification pattern, but that did not seem very convincing.
Are there any existing patterns/C# methodologies that I can use?
[Update: I ended up using a combination of the Annotations and the Specification pattern. The basic validations can be done via the annotations. If any special cases occur which cannot be validated via annotations, those validations are written via the specification]
You probably want to just use Attributes to specify your validation rules. This is the namespace where all the basic validations exist: ComonpentModel.DataAnnotations. If you want to get fancier, this NuGet package gives you lots of extra attributes: Data Annotation Extensions. Both of these support client side validation with ASP.NET’s MVC unobtrusive validation.