-
I'm working on converting a custom type of mine that represents a United States Social Security Number to use Vogen. One of the features I would like to preserve with this type is being able to return a At the moment, I have this: public static Result<SocialSecurityNumber> TryParseResult(string ssn)
{
Validation validationResult = Validate(NormalizeInput(ssn));
return validationResult == Validation.Ok
? From(ssn) // double validation
: new ValidationError(validationResult.Message); This code has not been tested, but should allow me to effectively replicate what Is there a better way of handling this situation? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @Foxtrek64 - thanks for the question. Yes, there is a better way that avoids exceptions. You can use the I hope that answers your question. |
Beta Was this translation helpful? Give feedback.
Hi @Foxtrek64 - thanks for the question. Yes, there is a better way that avoids exceptions. You can use the
TryParse
methods.One returns a
ValueObjectOrError
and one return abool
and takes anout
parameter.I've just documented these here. Please feel free to edit that page if anything could be improved (there's an 'Edit page' link at the top).
I've also added some unit tests here that demonstrate its use.
I hope that answers your question.