如何使用 AutoMapper 映射到具有私有字段的嵌套对象

How to map to nested object with private field using AutoMapper

我想做映射 CreateMap()

如何使用A​​utoMapper执行它?

 public class MoneyRangeSource
 {
    public string Start { get; set; }
    public string End { get; set; }
 }

 public class MoneyRangeDest
 {        
    public Money Start { get; set; }
    public Money End { get; set; }
 }

 public class Money
 {
   private string value;

   public Money(string money)
   {            
      value = money;
   }
 }

stringMoney 的转换设置 custom type converter
这允许将参数传递给 Money class

constructor
CreateMap<string, Money>().ConvertUsing(src => new Money(src));

和从 MoneyRangeSourceMoneyRangeDest

的正则映射
CreateMap<MoneyRangeSource, MoneyRangeDest>()