BuilderGenerator
BuilderGenerator copied to clipboard
Required props produce CS7036
When working with required/init props (e.g. in records), the generated code has the following error:
FooBuilder.g.cs(64,38): Error CS7036 : There is no argument given that corresponds to the required parameter 'Bar' of 'Foo(string, int)'
Simple example to reproduce:
public record Foo(string Bar, int Baz);
[BuilderFor(typeof(Foo))]
public partial class FooBuilder { }
or:
public class Foo
{
public required string Bar { get; init; }
public required int Baz { get; init; }
public Foo(string bar, int baz)
{
Bar = bar;
Baz = baz;
}
}
[BuilderFor(typeof(Foo))]
public partial class FooBuilder { }
/edit just to narrow this down further:
public class Foo
{
public required string Bar { get; init; }
public required int Baz { get; init; }
}
[BuilderFor(typeof(Foo))]
public partial class FooBuilder { }
works as expected.