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

Mapster.Tool: Destination transform is not correctly handled when UseDestinationValue is used #599

Closed
rafalka opened this issue Jun 27, 2023 · 0 comments · Fixed by #601
Closed

Comments

@rafalka
Copy link

rafalka commented Jun 27, 2023

Mapster.Tool does not properly handle situation when both UseDestinationValue() and AddDestinationTransform() is used and generates coalesce (??) on void collection copy method.

Example:
Declaration:

public class Src
{
    public IList<string> ListWithGetOnly { get; } = new List<string>();
}

public class Dst
{
    public List<string> ListWithGetOnly { get; } = new List<string>();
}

Mapper configuration:

            config.Default
                .UseDestinationValue(member => member.SetterModifier == AccessModifier.None &&
                                               member.Type.IsGenericType &&
                                               IsAssignableToGeneric(member.Type, typeof(ICollection<>)))
                .AddDestinationTransform(DestinationTransform.EmptyCollectionIfNull);

            config.ForType<Src, Dst>()
                .GenerateMapper(MapType.Map);

What gets generated:

      public static MapLib.MapTest.Dst AdaptToDst(this MapLib.MapTest.Src p1)
        {
            if (p1 == null)
            {
                return null;
            }
            MapLib.MapTest.Dst result = new MapLib.MapTest.Dst();
            
            funcMain1(p1.ListWithGetOnly, result.ListWithGetOnly) ?? new System.Collections.Generic.List<string>();
            return result;
        }
        
        private static System.Collections.Generic.List<string> funcMain1(System.Collections.Generic.IList<string> p2, System.Collections.Generic.List<string> p3)
        {
              ...
       }

Sample project:
MapsterBug-DestinationTransform.zip

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