Open EniacMlezi opened 1 year ago
@andrerav should we remove this part entirely and just generate the part with initialization values? @EniacMlezi can you mention the complete source code, please
@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
@EniacMlezi can you mention the complete source code, please
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: https://github.com/EniacMlezi/Mapster/commit/38401039547e1e5d800b634d92d5765c5eb28ae7
When using the c#11.0 required feature, the generated mappers fail. Editinh Sample.CodeGen for example:
And looking at the generated StudentMapper: