Skip to content

Mapster.Tool generates incorrect mapping extension method names when a destination type is nullable or generic #580

@rafalka

Description

@rafalka

Mapster.Tool generates incorrect mapping extension method names when a destination type is nullable or generic

Example:
Declaration:

    public class GenericTestSrc
    {
        public int Val { get; set; }
    }
    public class GenericTestDst<T>
    {
        public T Val { get; set; }
    }

    public record MyDateTime(DateTime? DateTime);

Mapper config:

            config.ForType<MyDateTime, DateTime?>()
                .MapWith(s => s.DateTime.Value )
                .GenerateMapper(MapType.Map);

            config.ForType<GenericTestSrc, GenericTestDst<int>>()
                .GenerateMapper(MapType.Map);

What gets generated:

        public static System.DateTime? AdaptToDateTime?(this MapLib.MapTest.MyDateTime s)
        {
            return (System.DateTime?)s.DateTime.Value;
        }

        public static MapLib.MapTest.GenericTestDst<int> AdaptToGenericTestDst<int>(this MapLib.MapTest.GenericTestSrc p1)
        {
            return p1 == null ? null : new MapLib.MapTest.GenericTestDst<int>() {Val = p1.Val};
        }

Attached sample project:
MapsterBug.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