-
-
Notifications
You must be signed in to change notification settings - Fork 380
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
New Url.TryParse method, and possibly breaking change for Url.Parse #696
Comments
Thank you for the well-thought-out idea and I apologize that it slipped through the cracks. Given that All of that said, I will leave this open for future consideration. |
I'm starting to warm up to this idea. At the very least, I think |
I'll add another vote for TryParse. As of now, it's easier to use Uri.TryCreate and then pass the Uri output variable to create a Flurl Url (shown below). I'd rather not have to use Uri at all.
|
This feature request has two parts:
Part 1 - TryParse
I think it would be beneficial to add a
TryParse
static method to theUrl
class. This would act similar toint.TryParse
. An example of it's usage would be:The
TryParse
would remove the need to have a method such as this (using 3.0.6)Currently,
Url.Parse()
andnew Url(string)
don't actually do any parsing; they're lazy.EnsureParsed
(the private instance method) only gets called when accessing one of the Url's properties. This means that aUrl
object can be successfully constructed from an improperly formatted URL string, and an exception will only be thrown when a property is used.While
TryParse
could be implemented with my example implementation above, I think it would be better for theUrl
class to callEnsuredParse
itself after the constructor has been run because it has access to it.Part 2 - Parse should parse
This will cause a breaking change, and I 100% understand if it's not feasible.
int
hasParse
andTryParse
. Both methods attempt to convert a string into an integer, butParse
will let exceptions bubble up whileTryParse
will capture the exception and instead return a boolean based on if one was thrown.As a developer, I would expect the
Parse
method to throw an exception if the value I pass it can't be parsed. That's true withint.Parse
, that's not true withUrl.Parse
.The text was updated successfully, but these errors were encountered: