public static bool TryParse(string value, out CustomerReferenceNumber result) { var segments = value .Split(Separator); if (segments.Length != NumberSegments) { result = null; return(false); } var codeValue = segments[CodeIndex]; var timestampValue = segments[TimestampIndex]; var alphaNumeric = segments[AlphaNumericIndex]; if (!TryParseCode(codeValue, out char code) || !TryParseTimestamp(timestampValue, out DateTime timestamp)) { result = null; return(false); } if (!IsValidCode(code) || !IsValidTimestamp(timestamp) || !IsValidAlphanumeric(alphaNumeric)) { result = null; return(false); } result = new CustomerReferenceNumber(timestamp, alphaNumeric); return(true); }
private void ValidateReferenceNumber(CustomerReferenceNumber referenceNumber) { if (referenceNumber == null) { throw new DomainException("Reference number cannot null"); } }
public Customer(CustomerIdentity id, CustomerReferenceNumber referenceNumber, string firstName, string lastName) : base(id) { ValidateReferenceNumber(referenceNumber); ReferenceNumber = referenceNumber; FirstName = firstName; LastName = lastName; }