Esempio n. 1
0
        private static void DoParse(string value, out PersonFullName result, out System.Exception exception)
        {
            if (string.IsNullOrWhiteSpace(value)) {
                result = null;
                exception = new FormatException("Value is null, empty or whitespace.");
                return;
            }

            string[] parts = value.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries);

            if (parts.Length < 2) {
                result = null;
                exception = new FormatException("Full name shall have at least 2 names.");
                return;
            }

            var surname = new Name(parts.Last());
            IEnumerable<Name> givenNames = parts.Take(parts.Length - 1).Select(name => new Name(name));
            result = new PersonFullName(surname, givenNames.ToArray());
            exception = null;
        }
Esempio n. 2
0
 public static bool TryParse(string fullName, out PersonFullName result)
 {
     System.Exception exception;
     DoParse(fullName, out result, out exception);
     return result != null;
 }
Esempio n. 3
0
 private bool Equals(PersonFullName other)
 {
     Contract.Assert(other != null);
     return Surname.Equals(other.Surname) && GivenNames.SequenceEqual(other.GivenNames);
 }