MapsterMapper / MapsterMapper/Mapster
When using TypeAdapterConfig.GlobalSettings.Default.IgnoreNullValues(true), it causes the Mapper function to be called twice.
@DocSvartz is already working on this.
Since Jan 30, 2025.
- Dominant language
- C#
- Stars
- 5.2k
- Forks
- 410
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 6
Description
There is example code following this. When Adapt() is called, it can be seen from the console that SummaryDetail runs twice. I would like to ask what is the reason for this and how to avoid it. I have also uploaded the test code for the entire project in the attachment. Thank you all for helping me answer this.
Please attach the test code file, and I will take a look to provide further assistance.
[TestMapster.zip](https://github.com/user-attachments/files/17901999/TestMapster.zip)
Program.cs:
TypeAdapterConfig.GlobalSettings.Default.IgnoreNullValues(true);
TypeAdapterConfig.GlobalSettings.Scan(Assembly.Load("TestMapster"));
TestInput.cs:
public class TestInput
{
public string Summary { get; set; }
}
public class TestView
{
public string Summary { get; set; }
}
MapperConfig.cs
public class MapperConfig : IRegister
{
public void Register(TypeAdapterConfig config)
{
config.ForType()
.Map(dest => dest.Summary, src => SummaryDetail(src.Summary))
;
}
private static string SummaryDetail(string s)
{
Console.WriteLine($"================{s}================");
return s + " plus";
}
}
Controller.cs
[HttpGet]
public TestView Get()
{
var input = new TestInput { Summary = "Hello World" };
return input.Adapt();
}
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.
Assessment
This issue has not been assessed yet.