mapperly: Cannot map `Value` or `HasValue` Property of `Nullable`
Describe the bug I upgraded from next-2 to next-3 and now I am receiving a build error
ModelMapper.g.cs(705,78): error CS1061: 'JsonElement' does not contain a definition for 'Value' and no accessible extension method 'Value' accepting a first argument of type 'JsonElement' could be found (are you missing a using directive or an assembly reference?)
It looks like the generated code is calling .Value twice:
// Generated code
{
var target = new global::SellerAmend()
{
Kind = source.Kind,
SellerPartnerId = source.SellerPartnerId,
SellerLoanId = source.SellerLoanId,
DateCreated = source.DateCreated
};
if (source.ListingAmendment != null)
{
// .Value.Value should just be .Value
target.ListingAmendmentValue = source.ListingAmendment.Value.Value.ToString();
}
return target;
}
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 15 (6 by maintainers)
@TimothyMakkison The test you provided, which should reproduce the bug described by OP, fails on v2.8.0. So this probably exists since a longer time and isn’t a regression of
v2.9.0-next.3@TimothyMakkison sorry my bad, I adjusted the test to verify that the bug does not exist. If I use exact your version, it fails on
v2.8.0as well as onv2.9.0-next.3. The problem is that the target property has a auto-flattened name of ending withValue. When resolving the name, autoflattening resolves it toP.Value(the value property ofNullable<T>). Then when building the mapping, the builder encounters a nullable value type and adds another.Valueto access the value inside the null if condition. It relates to https://github.com/riok/mapperly/issues/572. IfNullable<T>properties are treated asTwhile resolving mappable members, the problem shouldn’t occur.Here’s a repro:
Thanks for the bug report, I’ll look into it.