How could we convert a displayed property value before it gets displayed.
See original GitHub issueHi everyone,
I’m currently trying to figure out how I could implement an extension in FluentValidation to be able to convert the displayed value of a property. This might seems strange, but in the framework we are using right now, some values are saved in specific units but displayed in another one. Therefore, I would like the validation to display the unit correctly.
As an example, I might have a class with a property Weight
that is saved in kg but displayed in lb. When I do validate the property using Fluent Validation, the value that is being validated is in kg (which is good), but the error displayed is in kg (which is bad).
I know that I could have override all the validation to use custom message, but I was trying to find an easier solution. I’ve tried to replace some of the Fluent Validation option, but some classes are not accessible (they are internal). Therefore I’m a little bit stuck.
The other solution would be to validate the converted unit, which would work but requires some changes in the current framework, which I don’t think is a good solution.
Thanks for your help.
Issue Analytics
- State:
- Created 6 years ago
- Comments:13 (8 by maintainers)
Top GitHub Comments
Thanks, I’m glad its working. I’ll close this for now.
For the next release I’ll extend this to make
AbstractComparisonValidator.GetComparisonValue
public too.How’re you defining your rule? It should be populated if the comparison is a constant value. If you’re comparing to another property then MemberToCompare will be populated instead. You could also retrieve it from the MessageFormatter (which I think you were doing before)