Пример #1
0
        private ContactName ParseName()
        {
            var name = new ContactName
            {
                First  = string.Empty,
                Last   = string.Empty,
                Middle = string.Empty,
            };

            var parts = txtName.Text.Split(' ').ToList();

            if (parts.Count == 1)
            {
                name.First = parts[0];
            }
            else if (parts.Count == 2)
            {
                name.First = parts[0];
                name.Last  = parts[1];
            }
            else if (parts.Count > 2)
            {
                name.Last   = parts.PopLast();
                name.Middle = parts.PopLast();
                name.First  = string.Join(" ", parts);
            }

            return(name);
        }
Пример #2
0
 public static ContactName Duplicate(this ContactName name)
 {
     return(new ContactName
     {
         First = name.First.Duplicate(),
         Last = name.Last.Duplicate(),
         Middle = name.Middle.Duplicate(),
     });
 }
Пример #3
0
 public static string GetDisplay(this ContactName name)
 {
     string[] values = new[] { name.First, name.Middle, name.Last };
     return(string.Join(" ", values.Where(s => !string.IsNullOrWhiteSpace(s))));
 }