Skip to content

Required props produce CS7036 #62

@jdrst

Description

@jdrst

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions