Given a validator extending AbstractValidator and implementing IValidator, I would like to get it's rules. There seems to be no way to do this?
Asked
Active
Viewed 2,804 times
9
-
What do you mean? Are you trying to disassemble CLR? – Display Name Mar 11 '13 at 22:35
-
No, I just want to call a method to get a validator's rules. I will post the answer. – Shumii Mar 12 '13 at 11:25
1 Answers
4
Use the GetEnumerator method from the IValidator interface.
By enumerating through the collection you can inspect the validators applied to each property.
However, it got quite complex when dealing with DelegatingValidators so instead I applied a custom state with a .WithState() onto my validators which I could easily understand.

Shumii
- 4,529
- 5
- 32
- 41
-
8
-
1
-
If your IValidator is a subclass of AbstractValidator, it implements the IEnumerable interface so you can iterate over it: `var validationRules = MyValidator as IEnumerable
;` – BalintPogatsa May 09 '19 at 09:40