示例#1
0
        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);
        }
示例#2
0
 private void ValidateReferenceNumber(CustomerReferenceNumber referenceNumber)
 {
     if (referenceNumber == null)
     {
         throw new DomainException("Reference number cannot null");
     }
 }
示例#3
0
        public Customer(CustomerIdentity id,
                        CustomerReferenceNumber referenceNumber,
                        string firstName,
                        string lastName)
            : base(id)
        {
            ValidateReferenceNumber(referenceNumber);

            ReferenceNumber = referenceNumber;
            FirstName       = firstName;
            LastName        = lastName;
        }