MapsterMapper / MapsterMapper/Mapster
"IgnoreIf" doesn't work for records
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 5.2k
- Forks
- 410
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
Hi. In version 10.0.11, "IgnoreIf" doesn't work as it did in version 7... My mapper is written like this:
.Map(ask => ask.BoxPost, crm => crm.GetValue<AddressEntity, string?>(nameof(AddressEntity.BoxPost)))
.IgnoreIf((d, ask) => !d.ContainsKey<AddressEntity>(nameof(AddressEntity.BoxPost)), nameof(AddressEntity.BoxPost))
previously, in version 7, the following mapper code was generated:
.If (
.Call ReForm.Ism.Core.Serialization.Extensions.JsonObjectExtension.ContainsKey(
$var1,
"BoxPost")
) {
.Block() {
$result.BoxPost = .Invoke (.Lambda #Lambda2<System.Func`3[System.String,System.Nullable`1[System.Decimal],System.Nullable`1[System.Decimal]]>)(
.Call ReForm.Ism.Core.Serialization.Extensions.JsonObjectExtension.GetValue(
$var1,
"BoxPost"),
$result.BoxPost)
}
} .Else {
.Default(System.Void)
};
and now I get this:
BoxPost = .Invoke (.Lambda #Lambda2<System.Func`2[System.String,System.Nullable`1[System.Decimal]]>)(.Call ReForm.Ism.Core.Serialization.Extensions.JsonObjectExtension.GetValue(
$var1,
"BoxPost")),
It turns out that the presence of "IgnoreIf" does not change anything.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the reported mapper snippets in Mapster 10.0.11 and compare the generated expression with version 7. Focus on the IgnoreIf handling for records and verify the fix with a regression test showing that the generated mapping respects the key check and leaves BoxPost unchanged when the key is absent.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 57/100