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

Issue #54 Makes pass/fail of MapUsing explicit #71

Merged
merged 6 commits into from
Oct 31, 2020

Conversation

dustykline
Copy link
Contributor

I'd like to see the MapUsing changes for #54 make it to NuGet. I took a look at the existing work and the one place that I think there was some concern was in CsvRowMapping.TryMapValue, where the measure of whether or not a MapUsing delegate was successful was based on whether it raised an exception. You had a TODO comment there saying that "better error handling is a must" -- of course this is true, but the nature of MapUsing is that it embeds user-code within the main parsing loop, so it is implicitly dangerous.

My main change here is to change the MapUsing delegate from an Action<TEntity, TokenizedRow> to a Func which accepts the same inputs but returns a boolean. This allows MapUsing implementers to mark a row as invalid without raising an exception, which would be quite costly inside the main parsing loop.

I've updated the existing MapUsing test to show how this works (returning false to invalidate the row). I've also added a new test within Examples to show how Polymorphic rows can be accomplished with MapUsing. I'd be glad to contribute user documentation for this feature too, if you agree it's ready to ship.

…xceptions as flow control), add examples.
@bytefish
Copy link
Collaborator

Looks Good!

Let me know, when you think the Pull Request is done, so we can merge it upstream.

@bytefish
Copy link
Collaborator

I just glanced at it from my mobile phone, I will take a deeper look into it tommorow (or sunday 😓) and give some more feedback. What I see definitely makes sense and is very useful. Please go ahead and thanks for contributing!

@dustykline
Copy link
Contributor Author

dustykline commented Oct 30, 2020

Added some documentation, but I'm not setup to build rst locally. If you'll check that the docs build and that the new tutorial ("custom mapping") looks okay to you?

I think there is some room to expand the tutorial to show how to use secondary maps for mapping non-scalar types (like I do in the Polymorphic example test) -- but I was concerned that diving into that might be overwhelming for someone just trying to get MapUsing working.

If you're satisfied with this, I'm happy with it & I did re-run all unit tests prior to the PR. I think it'd be great to get NuGet updated for people (as well as myself 😄).

As a future extension of this work, there might be some good options to incorporate "secondary" maps into the top-level CsvMapping -- I'd be happy to chat with you about that possibility sometime.

edit The one decision I think needs made: Should this ship with the old (Action, not Func) MapUsing signatures present but flagged as Obsolete, like I did here, or should they be omitted entirely? My thought was that this version could ship with them deprecated, in case anyone has been using a custom fork during the past 1Y+ that the signature has been in master but not in NuGet. That way if someone reverts to the NuGet package, at least their code will reference the deprecated method, which will then instruct them what to change -- instead of their old code just being an unresolved method call.

@bytefish
Copy link
Collaborator

bytefish commented Oct 31, 2020

I don't think MapUsing is used extensively up to now, also due to a lack of description on my side. I wouldn't mark it as obsolete, it may be best to call it a breaking change and release a new Major version along with the docs.

@bytefish bytefish merged commit 423fd3e into TinyCsvParser:master Oct 31, 2020
@bytefish
Copy link
Collaborator

@dustykline I have updated the License, so it doesn't add my name everywhere. I have built and added the documentation to the gh-pages branch. Uploaded the package to NuGet and it should be listed soon. As for MapUsing I have simply removed the obsolete method, which apparently has never been released. Let's just throw it away. Let me know, if there is something missing.

@dustykline
Copy link
Contributor Author

dustykline commented Oct 31, 2020

@bytefish - Awesome! Glad I could help. FWIW, I’m also dad to a young girl with baby 2 on the way, but in between working & dad-ing, I’d be glad to collaborate more on your 3.0/rewrite goals. I really like Tiny compared to Helper, since a lot of my projects target resource-constrained platforms like Xamarin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants