StefH/FluentBuilder

Generating a builder for a property of a type where the ctor with the least parameters expects the property type itself causes a stack overflow

iam-mholle opened this issue · 1 comments

FluentBuilderGenerator.Extensions.TypeSymbolExtensions.GetNewConstructor always selects the ctor with the least parameters and fills in a fitting default by calling GetDefault for the expected ctor parameters.

For the following class, an infinite nesting of new Person(new Person(/*...*/)) is generated, leading to stack overflow.

public class Person
{
  public Person(string firstName, string lastName)
  {
    FirstName = firstName;
    LastName = lastName;
  }

  public Person(Person person)
  {
    FirstName = person.FirstName;
    LastName = person.LastName;
  }

  public string FirstName { get; set; }
  public string LastName { get; set; }
}

[AutoGenerateBuilder]
public partial class SomeDTO
{
  public Person Person { get; set; }
}