Пример #1
0
        public NameDetails buildFromLine(String line)
        {
            if (!canBuildFromLine(line))
            {
                throw new InvalidOperationException("Cannot handle line");
            }

            line = line.Trim();
            String[] parts = line.Split(" ");

            debugLines.Add("parts = " + parts.Length);


            String firstName = parts[0];
            String lastName  = parts[parts.Length - 1];

            // List<String> others = new List<String>();
            List <String> others = null;

            if (parts.Length > 2)
            {
                others = new List <String>();

                for (int i = 1; i < parts.Length - 1; i++)
                {
                    String part = parts[i];
                    debugLines.Add("part = " + part);

                    if (!String.IsNullOrEmpty(part))
                    {
                        debugLines.Add("adding = " + part);
                        others.Add(part);
                    }
                }
                debugLines.Add("others.size=" + others.Count);
            }



            NameDetails details;

            if (others != null)
            {
                debugLines.Add("3 args");
                details = new NameDetails(lastName, firstName, others);
            }
            else
            {
                debugLines.Add("2 args");
                details = new NameDetails(lastName, firstName);
            }

            return(details);
        }
Пример #2
0
        public String generateLine(NameDetails name)
        {
            String line = name.FirstName + " ";

            if (name.OtherNames != null)
            {
                foreach (String other in name.OtherNames)
                {
                    line = line + other + " ";
                }
            }

            line = line + name.LastName;

            return(line);
        }