Skip to content

ToRootTarget is not mapped in IEnumerable's #69

@SlowLogicBoy

Description

@SlowLogicBoy

When I map IEnumerable<FromModel> to IEnumerable<ToModel> with mapper configured with ToRootTarget(), ToModel instances have SubPropertyA and SubPropertyB == null
Code to reproduce: (used dotnet-script)

#r "nuget: AgileObjects.AgileMapper, *"
#r "nuget: Bogus, *"
using AgileObjects.AgileMapper;

var lorem = new Bogus.DataSets.Lorem(); //For model generation

//Configure Mapper
var mapper = Mapper.CreateNew();
mapper.WhenMapping
    .From<FromModel>()
    .To<ToModel>()
    .Map((s, t) => s.FromSubModel)
    .ToRootTarget();

//Generate FromModels
var fromModels = Enumerable.Range(0, 100)
    .Select(i => new FromModel {
        PropertyA = lorem.Word(),
        PropertyB = lorem.Word(),
        FromSubModel = new FromSubModel{
            SubPropertyA = lorem.Word(),
            SubPropertyB = lorem.Word()
        }
    });

//Map
var toModels = mapper.Map(fromModels).ToANew<IEnumerable<ToModel>>();
Debugger.Break();

class FromModel
{
    public string PropertyA { get; set; }
    public string PropertyB { get; set; }
    public FromSubModel FromSubModel { get; set; }
}

class FromSubModel
{
    public string SubPropertyA { get; set; }
    public string SubPropertyB { get; set; }
}

class ToModel
{
    public string PropertyA { get; set; }
    public string PropertyB { get; set; }
    public string SubPropertyA { get; set; }
    public string SubPropertyB { get; set; }
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions