BuilderGenerator icon indicating copy to clipboard operation
BuilderGenerator copied to clipboard

Required props produce CS7036

Open jdrst opened this issue 9 months ago • 0 comments

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.

jdrst avatar May 19 '25 08:05 jdrst