-
Notifications
You must be signed in to change notification settings - Fork 965
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
Change the return type of DehumanizeTo<TTargetEnum> to TTargetEnum #60
Comments
Now in case of no match, it returns null. After the change, it won't be possible. |
It could throw. You're asking to dehumanize a string into a wrong enum (or a wrong string into an enum) and an exception shouldn't be too much of a surprise. That said, I was actually going to implement it as a generic method in the beginning and couldn't - need generic constraint on enum (doable using Fody tho)! This was recently raised by a user on twitter and I created here if anyone is willing to give it a shot :) |
Thought about doing a constraint something like" : struct, IComparable, IFormattable, IConvertible" Regarding the excpetion, I'm not so familiar with the project, is there already any exception in the project that can be used in this case? |
Yeah, the constraint is cool. There is proper enum constraint here; but I'd rather Humanizer stay independent as much as possible. No existing exception. I'd create an explicit exception for this case. |
Done. Sent a pull request, please check it out and let me know what do you think. Another thing, I wasn't sure how to run the tests so it'll be nice to add a document that explains how to run them. |
Awesome. Thanks. Will do now. WRT running tests, they're just xUnit tests that you could run using TD.Net, R# (plus the xUnit plugin) or xUnit runner. They're also run with automatic PR verification through TeamCity as explained here. You can check your PR status on your PR now. It's green :) |
Thanks for the contribution. There were a few small things I raised on the PR. I'd appreciate if you could fix them and I will merge it in. |
OK. Fixed it and added to the test. |
Addressed in #69 |
It's a pain to have to cast back to the target enum every time.
The text was updated successfully, but these errors were encountered: