bchavez / Bogus

:card_index: A simple fake data generator for C#, F#, and VB.NET. Based on and ported from the famed faker.js.
Other
8.79k stars 499 forks source link

Person gender #423

Closed tcartwright closed 2 years ago

tcartwright commented 2 years ago

Please add a ctor that allows the gender to be specified when creating a new Person like so: Person(string locale, Name.Gender gender).

bchavez commented 2 years ago

Hello, thank you for creating an issue. You'll need to

  1. create a factory method, or
  2. inherit from Bogus.Person, or
  3. override Person.Populate() with your desired implmentation.

For example, option 2):

void Main()
{
   var male = new Person2(Name.Gender.Male);
   male.Dump();
}

public class Person2 : Bogus.Person
{
   public Person2(Name.Gender gender, string locale = "en") : base(locale)
   {
      this.Gender = gender;
      this.FirstName = this.DsName.FirstName(this.Gender);
      this.LastName = this.DsName.LastName(this.Gender);
      this.FullName = $"{this.FirstName} {this.LastName}";

      this.UserName = this.DsInternet.UserName(this.FirstName, this.LastName);
      this.Email = this.DsInternet.Email(this.FirstName, this.LastName);
   }
}

image