I've been using .Net languages for 4 years. I develop 3 tier and 5 tier applications using WCF, ASP.NET for web applications, and C# for windows applications. Every time I start a project, business rules and validations are a concern.
Where should I place custom validation rules (button-click events, page load, or in setters/getters within my classes)?
If a project is large and there is just a field that instead of 5 characters should be 7 characters - Why should I rebuild the whole project (or business classes project)?
I think if I had a file that had my custom rules, then when a change is needed I could simply place a new rule in it. I have read some articles on the internet that offer an XML based file for this purpose, but this seems problematic because:
- No Intellisense and errors in the XML file are very hard to find
- We have to write custom XML parsers
- Since this method requires numerous casts, it's very slow
My Question:
Is there a design pattern or anything else using .NET methods (Reflection, Expression Trees, Lambda Expressions, Dynamics, Runtime Creation of DLLs, etc.) to have dynamic validation using custom rules?
Edit 1)
What about Attributes? Can we use them with Reflection to Custom validations? Can we validate a property according another property(form example P1 should be P2+1) with this approach?