feat: add Try-prefixed methods
This PR adds Try-prefixed methods, including: TryConstruct, TryExecute, TryExtract.
This should also include the extension variant of the methods, which is where it tends to be used.
Thank you for the response. Extension methods added, please have a look!
Thanks for the pull request!
Is the primary goal to have versions of those methods that don't ever throw?
I notice that the new extraction plan now uses a class's TryParse method, which makes complete sense.
Does anyone know if there are any common types where Parse exists but TryParse doesn't?
A regex-matching text could throw any exception when parsing, e.g. OverflowException. So yes, performing an extraction that never throw is the goal of this PR.
If we are talking about the C# system types, all of those having Parse methods will also definitely have the TryParse variants existed.
I would say to maintain compatibility with user-defined types that use a Parse(string) method, it can look for a TryParse method, and then fallback to the Parse method if one is not found.
Thanks for pointing this out. I'll implement an attempt to TryParse before falling back to Parse as soon as possible.
@duydang2311, I converted this to a Draft PR for now. Please mark it as Ready for review once it's ready. And let me know if you have any questions or if there's anything I can do to help. Thanks!
Thanks for the pull request!
Is the primary goal to have versions of those methods that don't ever throw?
I notice that the new extraction plan now uses a class's
TryParsemethod, which makes complete sense.Does anyone know if there are any common types where
Parseexists butTryParsedoesn't?
Once .NET 7 is available it can also check to see if the type is IParsable<T>