具有嵌套子容器的自动映射器

时间:2011-11-11 20:28:47

标签: c# automapper

根据作者在2.0版中的帖子

http://lostechies.com/jimmybogard/2011/09/29/automapper-2-0-nestedchild-containers/

但是这个测试不起作用,有人可以指出这里有什么不对吗?

要传递的测试,automapper必须调用ConstructServicesUsing中传递的代码,它不是

    public class Source
    {
        public int SomeValue { get; set; }
    }

    public class Destination
    {
        public Destination() { }

        public Destination(bool value)
        {
            this.WasCustom = true;
        }
        public bool WasCustom { get; private set; }
        public int SomeValue { get; set; }
    }


    [TestMethod]
    public void can_make_servicelocator_work()
    {
        Mapper.CreateMap<Source, Destination>();
        var source = new Source { SomeValue = 100 };
        var dest = Mapper.Map<Source, Destination>(source,
            (option) => option.ConstructServicesUsing((t) => new Destination(true)));
        Assert.IsTrue(dest.WasCustom);
    }

1 个答案:

答案 0 :(得分:1)

我在automapper论坛上问了同样的问题,据作者说,这将在2.1

中提供

here是链接