简体   繁体   English

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

[英]Automapper with nested child containers

According to author's post in version 2.0 根据版本2.0中的作者帖子

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

but this test doesnt work, can someone point out whats wrong here ? 但是此测试不起作用,有人可以指出这里有什么问题吗?

for the test to pass, automapper must call the code passed in ConstructServicesUsing, which it is not 为了使测试通过,自动映射器必须调用在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);
    }

i asked the same question on automapper forum, and according to the author, this would be available in 2.1 我在automapper论坛上问了同样的问题,据作者说,这将在2.1版中提供

here is the link 是链接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM