Automapper 将字符串映射到列表 <string> 不正确

Automapper mapping string to list<string> incorrectly

我有两个 classes

 public class SourceClass
{
    public Guid Id { get; set; }
    public string Provider { get; set; }
}


public class DestinationClass
{
    public Guid Id { get; set; }
    public List<string> Provider { get; set; }
}

我的映射如下:

CreateMap<SourceClass, DestinationClass>()
    .ForMember(destinationMember => destinationMember.Provider,
        memberOptions => memberOptions.MapFrom(src => 
            new List<string> { src.Provider ?? "" }));

现在,之前 DestinationClass 中的 ProviderProviders 并且映射工作正常。但是,在使两个 class 中的拼写一致之后,映射无法正常进行。

"Test" 从来源 class 映射到 ["T", "e", "s", "t"]。当每个 class 中的 属性 名称不同时,映射工作正常。

我用过:

  • 控制台应用程序
  • .NET 4.6.1
  • 最新稳定Automapper

这种行为不可重现:

static MapperConfiguration _conf;

static void Main(string[] args)
{
    var src = new SourceClass() { Id = Guid.NewGuid(), Provider = "FooProvider" };
    InitializeAutomapper();
    var mapper = _conf.CreateMapper();
    DestinationClass destinationClass = mapper.Map<DestinationClass>(src);
    Console.WriteLine(destinationClass.Provider[0]);
}

static void InitializeAutomapper()
{
    _conf = new MapperConfiguration(cfg => 
        cfg.CreateMap<SourceClass, DestinationClass>()
            .ForMember(destinationMember => destinationMember.Provider,
                memberOptions => memberOptions.MapFrom(src => 
                    new List<string> { src.Provider ?? "" })));
}

输出:

FooProvider