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

Add the Parse and TryParse static methods #85

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

lucasteles
Copy link

Add the .Parse and .TryParse static methods on all base templates.

They are common and expected methods for value types.

.TryParse is especially good because enables the use of custom types on ASP.NET Minimal Api routes

fix #30

@hankovich
Copy link

Looks great. Are you sure that Parse and TryParse for string-backed and nullable-string-backed ids should trim the passed string?

@lucasteles
Copy link
Author

@hankovich no I don't 😅,

It looked correct to me at first, usually it's undesired spaces at edges of the strings

Wdyt?

@hankovich
Copy link

@lucasteles I think Parse/TryParse should not do any additional manipulations, they should act as a shorthand for new TId(TBackedType.Parse(input))

If trimming will be added, it makes sense to trim in constructors, not inside parsing methods. And I'm not sure everyone needs they input to be trimmed

@lucasteles
Copy link
Author

Makes sense to me, I will update the the PR

@lucasteles
Copy link
Author

@hankovich updated

@gunnbr
Copy link

gunnbr commented Oct 12, 2023

Thank you, @lucasteles ! I thought I must be using this library wrong since I have to manually add the static .TryParse to each of my Ids to get minimal API routing to work properly.

@andrewlock , any chance of getting this or something similar merged into the release?

@lucasteles
Copy link
Author

Thank you, @lucasteles ! I thought I must be using this library wrong since I have to manually add the static .TryParse to each of my Ids to get minimal API routing to work properly.

I implemented it in my fork

https://github.com/lucasteles/Strongly

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.

[Proposal] Add Parse and TryParse methods for Guid/long/int-backed ids
3 participants