public static bool TryCreate(string emailAddress, out EmailAddress result, out string failureReason) { var specification = new EmailAddressSpecification(); if (specification.IsSatisfiedBy(emailAddress)) { result = new EmailAddress(emailAddress); failureReason = string.Empty; return true; } result = null; failureReason = specification.GetReasonsForDissatisfactionSeparatedWithNewLine(); return false; }
public static EmailAddress Create(string emailAddress) { if (emailAddress == null) { throw new ArgumentNullException("emailAddress"); } var specification = new EmailAddressSpecification(); if (specification.IsSatisfiedBy(emailAddress)) { return new EmailAddress(emailAddress); } throw new ArgumentException(string.Format("Email address '{0}' doesn't satisfy specification.", emailAddress), "emailAddress"); }