Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to only set target properties if it is null or default value #1336

Open
moxplod opened this issue Jun 13, 2024 · 1 comment
Open
Labels
enhancement New feature or request

Comments

@moxplod
Copy link

moxplod commented Jun 13, 2024

My use case is the enrichment of data in a class and I have sources that are more reliable than others. So if I use a less reliable source, then I do not want to overwrite an existing property if it already has a non-default value.

Something like this -

                    if (source.Twitter != null && target.Twitter != default)
                    {
                        target.Twitter = source.Twitter;
                    }

I am not sure if this exists; I tried finding it in the documentation and did not find it.

@moxplod moxplod added the enhancement New feature or request label Jun 13, 2024
@latonz
Copy link
Contributor

latonz commented Jun 14, 2024

This is not yet supported and would be a nice addition. Relates to the current MapperAttribute.AllowNullPropertyAssignment and #296.
A simple API for this could be introducing a MapperAttribute.MemberMappingPrecondition with enum { None = 0, SourceAndTargetNotEqual = 1 << 0, SourceNotNull = 1 << 1, TargetNotNull = 1 << 2 }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants