public static bool TryCreate(string phoneNumber, out PhoneNumber result, out string failureReason) { var specification = new PhoneNumberSpecification(); if (specification.IsSatisfiedBy(phoneNumber)) { result = new PhoneNumber(phoneNumber); failureReason = string.Empty; return true; } result = null; failureReason = specification.GetReasonsForDissatisfactionSeparatedWithNewLine(); return false; }
public static PhoneNumber Create(string phoneNumber) { if (phoneNumber == null) { throw new ArgumentNullException("phoneNumber"); } var specification = new PhoneNumberSpecification(); if (specification.IsSatisfiedBy(phoneNumber)) { return new PhoneNumber(phoneNumber); } throw new ArgumentException(string.Format("Phone number '{0}' doesn't satisfy specification.", phoneNumber), "phoneNumber"); }