public static bool TryCreate(string postalCode, out PostalCode result, out string failureReason) { var specification = new PostalCodeSpecification(); if (specification.IsSatisfiedBy(postalCode)) { result = new PostalCode(postalCode); failureReason = string.Empty; return true; } result = null; failureReason = specification.GetReasonsForDissatisfactionSeparatedWithNewLine(); return false; }
public static PostalCode Create(string postalCode) { if (postalCode == null) { throw new ArgumentNullException("postalCode"); } var specification = new PostalCodeSpecification(); if (specification.IsSatisfiedBy(postalCode)) { return new PostalCode(postalCode); } throw new ArgumentException(string.Format("Postal code '{0}' does not satisfy specification.", postalCode), "postalCode"); }