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

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 #747

Open
WuQuDeRen opened this issue Dec 31, 2024 · 2 comments

Comments

@WuQuDeRen
Copy link

WuQuDeRen commented Dec 31, 2024

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

  // 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;
  })
@DocSvartz
Copy link

Hello @WuQuDeRen. Maybe you need Ignore conditionally or Map with condition .

@WuQuDeRen
Copy link
Author

WuQuDeRen commented Jan 6, 2025

Hello @WuQuDeRen. Maybe you need Ignore conditionally or Map with condition .

You're right, but when there are many attributes, configuring them one by one can be cumbersome. I need a universal and concise way。Similar to the IgnoreNullValues method, but I need to independently determine which values cannot be copied, such as empty strings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants