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

TryFrom - add overload returning validation result #743

Open
pawelwilczewski opened this issue Jan 26, 2025 · 1 comment
Open

TryFrom - add overload returning validation result #743

pawelwilczewski opened this issue Jan 26, 2025 · 1 comment
Labels
enhancement New feature or request

Comments

@pawelwilczewski
Copy link

Describe the feature

Currently, it's possible to use the validation result only if you use the ErrorOr overload:

var result = FilePath.TryFrom("X:/test");
if (!result.IsSuccess)
{
	Console.Out.WriteLine("Validation error occurred: {0}", result.Error.ErrorMessage);
}

An overload could be added so the boolean version of TryFrom also returns the validation result - as an out parameter:

if (!FilePath.TryFrom("X:/test", out var filePath, out var validationResult))
{
	Console.Out.WriteLine("Validation error occurred: {0}", validationResult.ErrorMessage);
}

I find the latter to be a lot more convenient to write. I am new to this repository, please let me know if this does not align with the vision or might not be a good idea for certain reasons. I can contribute.

Thank you!

@pawelwilczewski pawelwilczewski added the enhancement New feature or request label Jan 26, 2025
@SteveDunn
Copy link
Owner

Thanks for the feedback! I think that would make a useful addition.

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

No branches or pull requests

2 participants