Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Commit

Permalink
fix - Fixed names list not changing according to gender
Browse files Browse the repository at this point in the history
We've fixed names list not being updated according to the gender

---

When we're trying to get the names list, we should update the names list to accomodate the changes made to the requested gender.

---

Type: fix
Breaking: False
Doc Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Oct 14, 2023
1 parent b952705 commit 91a5651
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Namer.Demo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static void Main()

// Generate 5 names with custom name prefix
Console.WriteLine("Generate 5 names with custom name prefix\n");
var names5nameprefix = NameGenerator.GenerateNames(5, "J", "m", "", "", genderType);
var names5nameprefix = NameGenerator.GenerateNames(5, "J", "n", "", "", genderType);
Console.WriteLine("- {0}\n", string.Join(", ", names5nameprefix));

// Generate 5 names with custom surname prefix
Expand Down
4 changes: 3 additions & 1 deletion Namer/NameGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public static class NameGenerator
{
internal static string[] Names = Array.Empty<string>();
internal static string[] Surnames = Array.Empty<string>();
private static NameGenderType lastGenderType = NameGenderType.Unified;
private static readonly HttpClient NameClient = new();
private static readonly string nameAddressPart = "https://cdn.jsdelivr.net/gh/Aptivi/NamesList@latest/Processed/";
private static readonly string unifiedNameListFileName = "FirstNames.txt";
Expand Down Expand Up @@ -68,10 +69,11 @@ public static async Task PopulateNamesAsync(NameGenderType genderType = NameGend
unifiedNameListFileName;
string nameAddress = $"{nameAddressPart}{namesFileName}";

if (Names.Length == 0)
if (Names.Length == 0 || genderType != lastGenderType)
Names = await PopulateInternalAsync(nameAddress);
if (Surnames.Length == 0)
Surnames = await PopulateInternalAsync(surnameAddress);
lastGenderType = genderType;
}
catch (Exception ex)
{
Expand Down

0 comments on commit 91a5651

Please sign in to comment.