Vogen icon indicating copy to clipboard operation
Vogen copied to clipboard

TryFrom - add overload returning validation result

Open pawelwilczewski opened this issue 11 months ago • 1 comments

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 avatar Jan 26 '25 22:01 pawelwilczewski

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

SteveDunn avatar Feb 13 '25 06:02 SteveDunn