/// <summary>
 ///     Creates a random name using the specified format.
 /// </summary>
 /// <param name="format">The name format.</param>
 /// <returns>A random name with the specified format.</returns>
 /// <include file='Docs/NameFormatsExample.xml' path='example' />
 public static string FullName(NameFormats format)
 {
     lock (s_formatMapLock)
     {
         return(string.Join(" ", s_formatMap[format].Invoke()));
     }
 }
示例#2
0
        /// <summary>
        /// Returns the name of this <see cref="Person"/> in the specified
        /// format.
        /// </summary>
        /// <param name="nameFormat">
        /// Format to generate and return
        /// </param>
        /// <returns>
        /// Returns the name of this <see cref="Person"/> in the
        /// specified <see cref="NameFormats"/>.
        /// </returns>
        public string GetFormattedName(NameFormats nameFormat)
        {
            if (nameFormat == NameFormats.FirstMiddleInitialLast)
            {
                if (!string.IsNullOrEmpty(this.MiddleName))
                {
                    return(string.Format("{0} {1}. {2}", this.FirstName, this.MiddleName.Substring(0, 1).ToUpper(), this.LastName));
                }
                else
                {
                    return(string.Format("{0} {1}", this.FirstName, this.LastName));
                }
            }
            else if (nameFormat == NameFormats.LastFirstMiddleInitial)
            {
                if (!string.IsNullOrEmpty(this.MiddleName))
                {
                    return(string.Format("{0}, {1} {2}.", this.LastName, this.FirstName, this.MiddleName.Substring(0, 1).ToUpper()));
                }
                else
                {
                    return(string.Format("{0}, {1}", this.LastName, this.FirstName));
                }
            }

            return(string.Empty);
        }
示例#3
0
 /// <summary>
 ///     Creates a random name using the specified format.
 /// </summary>
 /// <param name="format">The name format.</param>
 /// <returns>A random name with the specified format.</returns>
 /// <include file='Docs/NameFormatsExample.xml' path='example' />
 public static string FullName(NameFormats format)
 {
     lock (s_formatMapLock)
     {
         return string.Join(" ", s_formatMap[format].Invoke());
     }
 }
示例#4
0
        /**
         * This method is used to sort a list of names contained in a .txt file. It takes a file path and the format that
         * corresponds to the format of the names within the file.
         */
        public void Sort(string path, NameFormats format, bool isAscending)
        {
            var names = ExtractNames(path, format);

            if (names == null)
            {
                return;
            }

            names = isAscending ? names.OrderBy(s => s.Forenames).ThenBy(s => s.Surname).ToArray() :
                    names.OrderByDescending(s => s.Surname).ThenByDescending(s => s.Forenames).ToArray();

            OutputToFile(path, names);
        }
示例#5
0
        public string GetName(NameFormats format)
        {
            switch (format)
            {
            case NameFormats.Last:
                return(name.LastName);

            case NameFormats.First:
                return((name.FirstName) ?? "");

            case NameFormats.Type:
                return(type.Name);

            case NameFormats.First_Last:
                return((!(string.IsNullOrEmpty(name.FirstName)) ? name.FirstName + " " : "") + name.LastName);

            case NameFormats.Last_First:
                return(name.LastName + ((!string.IsNullOrEmpty(name.FirstName)) ? (", " + name.FirstName) : ""));

            case NameFormats.First_Last_Type:
                if (this.type_id == 3 || type_id == 4 || type_id == 5)
                {
                    return(GetName(NameFormats.First_Last));
                }
                else
                {
                    return(GetName(NameFormats.First_Last) + ", " + type.Name);
                }

            case NameFormats.Last_First_Type:
                if (this.type_id == 3 || type_id == 4 || type_id == 5)
                {
                    return(GetName(NameFormats.Last_First));
                }
                else
                {
                    return(GetName(NameFormats.Last_First) + " (" + type.Name + ")");
                }

            default:
                return("");
            }
        }
示例#6
0
        /**
         * Function for extracting the arguments from the args input in the main function, it takes the input string
         * array directly and extracts the flags from it and also the fullpaths.
         */
        private static void ExtractArgs(string[] args)
        {
            var formatIndex = -1;

            _filePaths = new List <string>();
            foreach ((string value, int i) in args.Select((value, i) => (value, i)))
            {
                if (value.StartsWith("-"))
                {
                    switch (value.Substring(1))
                    {
                    case "a":
                        _ascending = true;
                        break;

                    case "d":
                        _ascending = false;
                        break;

                    case "f":
                        formatIndex = i + 1;
                        break;

                    default:
                        Console.WriteLine("Error Unrecognised Flag, the Flag \"" + value + "\" is going to be ignored!");
                        break;
                    }
                }
                else
                {
                    if (i == formatIndex)
                    {
                        _format = StringToNameFormat(value);
                    }
                    else
                    {
                        _filePaths.Add(value);
                    }
                }
            }
        }
示例#7
0
 /**
  * This function takes the inputted filepath and extracts the names from this file returning it as a Name object
  * array.
  */
 private Name[] ExtractNames(string filePath, NameFormats format)
 {
     try
     {
         var fileLines = _fileWrapper.ReadAllLines(filePath);
         var names     = new Name[fileLines.Length];
         Console.WriteLine("Names from File \"" + filePath + "\":");
         for (var i = 0; i < fileLines.Length; i++)
         {
             names[i] = new Name(fileLines[i], format);
             Console.WriteLine(names[i]);
         }
         Console.WriteLine("\n");
         return(names);
     }
     catch (FileNotFoundException e)
     {
         Console.WriteLine("File Not Found Exception. Msg: " + e.Message);
         return(null);
     }
 }
示例#8
0
        private void TestSort(bool order, NameFormats format, string[] input, string[] output)
        {
            string testOutPath = "sorted" + TestFilePath;

            Mock <IFileWrapper> mockFileWrapper = new Mock <IFileWrapper>();

            mockFileWrapper.Setup <string[]>(m => m.ReadAllLines(It.Is <string>(s => String.Compare(s, TestFilePath, StringComparison.Ordinal) == 0))).Returns(input);
            Mock <StreamWriter> streamWriter = new Mock <StreamWriter>(testOutPath);

            mockFileWrapper.Setup <StreamWriter>(m =>
                                                 m.GetStreamWriter(It.Is <string>(s =>
                                                                                  string.Compare(s, testOutPath, StringComparison.Ordinal) == 0)))
            .Returns(streamWriter.Object);

            global::NameSorter.NameSorter nameSorter = new global::NameSorter.NameSorter(mockFileWrapper.Object);
            nameSorter.Sort(TestFilePath, format, order);

            foreach (var line in output)
            {
                streamWriter.Verify(a => a.WriteLine(line), Times.Exactly(1));
            }
        }
示例#9
0
文件: Name.cs 项目: jhb15/NameSorter
        private void BuildNameFromRawString(string rawString, NameFormats format)
        {
            var nameComponents  = Regex.Split(rawString, @"\s+");
            var cleanComponents = SanitiseInputName(nameComponents);

            switch (format)
            {
            case NameFormats.InOrder:
                BuildNameFromInOrderString(cleanComponents);
                break;

            case NameFormats.Backwards:
                BuildNameFromBackwardsString(cleanComponents);
                break;

            case NameFormats.SurnameFirst:
                BuildNameFromSurnameFirstString(cleanComponents);
                break;

            default:
                Console.WriteLine("Error name format not recognised or implemented! Format used: " + format);
                break;
            }
        }
示例#10
0
文件: Name.cs 项目: DaveCS1/faker-cs
 /// <summary>
 ///     Create a name using a specified format.
 /// </summary>
 public static string FullName(NameFormats format)
 {
     return(string.Join(" ", FormatMap[format].Invoke()));
 }
示例#11
0
文件: Name.cs 项目: rally25rs/FakeO
 /// <summary>
 /// Create a name using a specified format.
 /// </summary>
 public static string FullName(NameFormats format)
 {
     return System.String.Join(" ", _formatMap[format].Invoke());
 }
示例#12
0
 public static string Name()
 {
     return(NameFormats.Random());
 }