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
Add validation msg to Validate Func #1266
Conversation
- Add a way to associate an exception message with Validate lambda. - Add Unit test to above functionality.
Does I think instead of a |
Something like this: public virtual new MemberMap<TClass, TMember> Validate(Func<string, bool> validateExpression, Func<string, string> validateMessageExpression)
{
Data.ValidateExpression = (Expression<Func<string, bool>>)(field => validateExpression(field));
Data.ValidateMessageExpression = (Expression<Func<string, string>>)(field => validateMessageExpression(field));
return this;
} |
|
I would think people would naturally want to put it in their message. $"Validation failed: Field '{field}' cannot contain spaces." |
I'll see what I can do, I'm trying now to figure out how to invoke that expression. But what would the expression achieve? like from your example the expression will execute and if evaluated not to true be passed along to the exception constructor like I did originally or something different? |
- Instead of string as paramter pass Func<string,string>. - Execute the Expression and use the result as exception message.
@JoshClose |
bump?? @JoshClose |
This could make life much easier for me. What's the status of this @micheleissa and @JoshClose? |
It'll still be at least a few weeks. I'm very swamped with work. |
Hi all, this feature would be super useful for me for too. Do you have any updates @JoshClose? I know a good software engineer is a busy software engineer. |
I'm looking for a resolution to this as well. Any word? |
As a work around, you can throw your own Exception type with its own message instead of returning false in your validation. That will get cauight and wrapped by CsvHelper in a CsvHelperException which will contain the context and the inner exception will be your exception, Catch the CsfHelperException and use the inner exception to get your message. |
Closes #1198