nickdodd79 / AutoBogus

A C# library complementing the Bogus generator by adding auto creation and population capabilities.
MIT License
423 stars 49 forks source link

[Enhancement] WithConventions aliases allow expression #92

Open c-conklin opened 1 year ago

c-conklin commented 1 year ago

AutoBogus.Conventions allow aliases to be configured, expanding the property name targets associated with a given convention mapping. The following adds AnotherEmail and AlternateEmail property names as candidates for the Email generator:

AutoFaker.Configure(builder =>
{
  builder.WithConventions(config =>
  {
    config.Email.Aliases(new [] { "AnotherEmail", "AlternateEmail" });  // Generates an email value for members named AnotherEmail & AlternateEmail
  });
});

Feature Request

Allow Aliases with expression parameter. Example:

AutoFaker.Configure(builder =>
{
  builder.WithConventions(config =>
  {
    config.Email.Aliases<EntityName>(propName => propName.Contains("Email"));  // Generates an email value for members with names containing Email
  });
});

Work Around

builder.WithConventions(config =>
  {
      var emailProps = (from prop in typeof(<EntityType>).GetProperties() where prop.Name.Contains("Email") select prop.Name).ToArray();
      config.Email.Aliases(emailProps);
  })

I'm unsure how much overhead or complexity is involved with such a feature. However, this is quite useful when dealing with large flattened entities.