Skip to content

Mapster.Tool: Member mapping is not generated when ShallowCopyForSameType and UseDestinationValue is used #600

@rafalka

Description

@rafalka

Mapster.Tool does not generate member mapping when ShallowCopyForSameType and UseDestinationValue is used and source and destination member type is same.
Example:
Declaration:

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

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

Mapper configuration:

      .ShallowCopyForSameType(true)
      .UseDestinationValue(member => member.SetterModifier == AccessModifier.None &&
                                     member.Type.IsGenericType &&
                                     IsAssignableToGeneric(member.Type, typeof(ICollection<>)))

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);
            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-UseDestinationValue.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions