-
Notifications
You must be signed in to change notification settings - Fork 338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generated mappers and required attributes #554
Comments
@andrerav should we remove this part entirely and just generate the part with initialization values? |
@stormaref That is tempting, but it will change a lot of code for a lot of people. I think a similar solution to the one in #545 is preferable. |
@andrerav that fix won't work with this problem because in that case, the problem was setting the init-only property, and this line was ok: _UserDto result = p4 ?? new _UserDto(); but in this case, the problem occurs on this line: Person result = p4 ?? new Person(); and that solution won't fix this problem |
The complete source code is the codegen sample in this repository (Sample.CodeGen), but with Person.Id made required and the C# langver set to support required. |
Check this: for code sample: EniacMlezi@3840103 |
Has anyone found a solution to this? |
@andrerav |
@andrerav @leetal This is what you need, right?
|
Essentially, yes :) But I fear that it might not work if using for example different classes and say that the required property would be non-existent (in your var1 above) by having custom DTOs with mapping configs as an example, then that would not work right? What would be a “sensible default” in those cases without having a way to actually populate the required field somehow? Or am I completely wrong? 🤔 |
If you use configuration. Then it will work too.
Without configuration, yes, it will not work. |
With this configuration, the result will be correct. (not work on 7.4.0)
|
@andrerav I opened a PR that I hope adds this improvement. )) |
When using the c#11.0 required feature, the generated mappers fail. Editinh Sample.CodeGen for example:
And looking at the generated StudentMapper:

The text was updated successfully, but these errors were encountered: