MapsterMapper / MapsterMapper/Mapster

wish to add the ability to ignore a copy of a property when it has a specific value. For example, null, empty string, empty collection

Open
#747 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Ignore features improvement waiting for info
Dominant language
C#
Stars
5.2k
Forks
410
Avg merge
2d 12h
Merged PRs (30d)
6

Description

mapster has provided the function of not copying the property when the value of the property is null. Can we extend this function to stop copying the property when the value of the property is a series of specific values? It is better to provide a general method (I am not sure which property and which type, but I am sure that the value cannot be these)? Determine whether a property field can be copied before it is copied

``` C#
// Can you provide such a method
// Another framework, automapper, already provides similar functionality
// I don't care about the attribute name, but I care about the attribute value, and providing the attribute name is best when determining the attribute value
IgnoreMember((srcMember, destMember, srcValue, destValue) =>
{
if (srcValue is string srcValueTxt)
{
return string.IsNullOrWhiteSpace(srcValueTxt);
}

if (srcValue == destValue)
{
return true;
}

return false;
})
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing Mapster's existing behavior for not copying null properties and the IgnoreMember API shown in the issue. Define how configured values such as null, empty strings, and empty collections should affect copying, then verify the behavior with mapping cases covering the requested values.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.