lundi 27 janvier 2020

AbstractValidator load by model type

This question is related to FluentValidation nugetpackage

I have a Person model and an Address model and they both inherit from class called RecordTypeModel. I have fluent PersonValidator and AddressValidator. I then have a class called CreateFile(RecordTypeModel model).

RecordTypeModel class has a property called RecordType

In CreateFile() when model.RecordType is Person then I want to create PersonValidator instance. But I dont want to have a bunch of switch/ifelse statements.

I have tried this

var validator = GetValidatorInstance($"{item.RecordType}Validator") as AbstractValidator; 

enter image description here But AbstractValidator of fluentValidation package forces to provide exact model.





Aucun commentaire:

Enregistrer un commentaire