AutoMapper 值转换器

http://docs.automapper.org/en/stable/Value-converters.html
public class CurrencyFormatter : IValueConverter<decimal, string> {
    public string Convert(decimal source)
        => source.ToString("c");
}
 cfg.CreateMap<Order, OrderDto>()
       .ForMember(d => d.Amount, opt => opt.ConvertUsing(new CurrencyFormatter()));
转换器 与 解释器 区别
  • Type converter = Func<TSource, TDestination, TDestination>  // 全局
  • Value resolver = Func<TSource, TDestination, TDestinationMember>  // 
  • Member value resolver = Func<TSource, TDestination, TSourceMember, TDestinationMember>
  • Value converter = Func<TSourceMember, TDestinationMember>  //只与成员相关

AutoMapper 值转换器

上一篇:VC++ MFC文件的移动复制删除更名遍历操作


下一篇:hadoop MapReduce自定义分区Partition输出各运营商的手机号码