Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert DTO attributes to ValidationRules #393

Closed
bickycheese opened this issue Jan 31, 2017 · 2 comments
Closed

Convert DTO attributes to ValidationRules #393

bickycheese opened this issue Jan 31, 2017 · 2 comments

Comments

@bickycheese
Copy link

bickycheese commented Jan 31, 2017

I'm trying to re-use the already existing attributes on my DTO's to create validation rules.
I've tried something on this Gist but I think it's not going to work because the compiler can't infer the property type from the expression. The not working part is commented out.

Any ideas? Or is there already something implemented to do this?

@JeremySkinner
Copy link
Member

You'd have to do it by constructing PropertyRule instances directly rather than trying to use expressions. Although FV's public api is strongly typed, internally it isn't so you can drop down to the internal api.

Take a look at the code for how RuleFor is defined...it creates a RuleBuilder and from that create PropertyRule from the expression, and then uses AddRule to store this in the validator. You'd need to do something similar.

@bickycheese
Copy link
Author

Ok, thanks @JeremySkinner, I'll look into that part and see if can contribute anything useful.

@lock lock bot locked and limited conversation to collaborators Aug 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants