Earlier quoted context omitted.
The problem is when you want validation errors which contains the field name, and a descriptive error message. Oh you want them localised as well? You then want each field to be validated individually. So you get an error for each field which is wrong. So you have if statements for each field creating a localised validation error object then placing in a list. You have 8 fields coming in on your request. It's startin…
> The problem is when you want validation errors which contains the field name, and a descriptive error message. Oh you want them localised as well? So the above example would become something like this: if (!string.IsNullOrEmpty(card.CardNumber) && CardNumberRegex.IsMatch(card.CardNumber)) validationContext.add("CardNumber", Localizer.MessageFor("InvalidCCNumber")); if (x.ExpirationMonth 12) validationContext.add("E…
Next problem, rename a field on the object using a refactoring tool. You now have to change validation code to change the field name. You may forget about the validation code if your not looking at it. You have good tests though so you would probably would catch it. But you want it to be automatic. Maybe nameof?
The class is getting a lot responsibility, and you want to seperate validation out into its own class responsible for that. Maybe extract to a validation object which operates on a request/command class?
Might point is you eventually you end up building something like fluent validation. With own set of default rules, validation classes etc. Maybe fluent validation is overly complicated but I'd rather get the speed boost of using a well tested library that I already know instead of gradually refactoring into something custom.