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

C# 具有嵌套子容器的自动映射,c#,automapper,C#,Automapper,根据作者在2.0版中的帖子 但是这个测试不起作用,有人能指出这里出了什么问题吗 为了使测试通过,automapper必须调用ConstructServicesUsing中传递的代码,而它不是 public class Source { public int SomeValue { get; set; } } public class Destination { public Destination() { }

根据作者在2.0版中的帖子

但是这个测试不起作用,有人能指出这里出了什么问题吗

为了使测试通过,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);
    }
公共类源代码
{
公共int SomeValue{get;set;}
}
公务舱目的地
{
公共目的地(){}
公共目的地(布尔值)
{
this.WasCustom=true;
}
公共bool WasCustom{get;private set;}
公共int SomeValue{get;set;}
}
[测试方法]
public void可以使服务定位器工作()
{
CreateMap();
var source=new source{SomeValue=100};
var dest=Mapper.Map(源、,
(option)=>option.ConstructServicesUsing((t)=>newdestination(true));
Assert.IsTrue(dest.WasCustom);
}

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


链接是否是

您希望发生什么?你看起来很困惑。你的代码毫无意义。我以为你会读代码,不管怎样,我希望测试通过,现在它失败了,为了通过,必须调用布尔arg的构造函数,而不是调用它,调用它的方法是使用在映射调用期间传递的构造函数func(而不是在初始化配置期间)我用2.2.1试过了,上面的测试还是失败了吗?