mapperly icon indicating copy to clipboard operation
mapperly copied to clipboard

Mapperly does not fully map classes that inherit/implement Collection types.

Open TimothyMakkison opened this issue 2 years ago • 0 comments

Describe the bug Mapperly does not correctly map classes that inherit from Collection types such as List or IEnumerable. It will ignore any properties on the target class and will not use parameterized constructors. Note that both source and target must be an inherit/implement Enumerable.

To Reproduce

[Mapper]
public static partial class Mapper
{
    public static partial Destination Map(Source src);
}

public class Source : List<int>
{
    public int MyLength { get; set; }
}

public class Destination : List<int>
{
    public int MyLength { get; set; }
}

Generates the following. Note how MyLength is not mapped.

public static partial global::Riok.Mapperly.Sample.Destination Map(global::Riok.Mapperly.Sample.Source src)
{
    var target = new global::Riok.Mapperly.Sample.Destination();
    target.EnsureCapacity(src.Count + target.Count);
    foreach (var item in src)
    {
        target.Add(item);
    }

    return target;
}

Expected behaviour Mapperly should iterate over the source mapping it and then map the properties.

TimothyMakkison avatar May 17 '23 09:05 TimothyMakkison