Files
CapMachine/CapMachine.Wpf/MapperProfile/ChartSelectProfile.cs
2024-07-04 17:42:03 +08:00

31 lines
1.6 KiB
C#
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using AutoMapper;
using CapMachine.Model;
using CapMachine.Wpf.Models;
namespace CapMachine.Wpf.MapperProfile
{
/// <summary>
/// 源类的属性名称和目标类的属性名称相同不区分大小写直接匹配Mapper.CreateMap<source,dest>();无需做其他处理,此处不再细述
/// 1智能匹配
///  AutoMapper能够自动识别和匹配大部分对象属性:
/// 如果源类和目标类的属性名称相同,直接匹配,不区分大小写
/// 目标类型的CustomerName可以匹配源类型的Customer.Name
/// 目标类型的Total可以匹配源类型的GetTotal() 方法
/// </summary>
public class ChartSelectProfile : Profile
{
public ChartSelectProfile()
{
CreateMap<ConfigChartSelect, ChartSelectDto>()
.ForMember(dest => dest.Index, opt => opt.MapFrom(src => src.Index))
.ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name))
//.ForMember(dest => dest.Id, opt => opt.Ignore())//忽略目标类中的属性
//.ForMember(dest => dest.OrderDate, opt => opt.UserValue<DateTime>(DateTime.Now)); //固定值匹配
//.ForMember(dest => dest.TotalAmount, opt => opt.MapFrom(src => src.TotalAmount ?? 0)) //复杂的匹配
//.ForMember(dest => dest.EventDate, opt => opt.MapFrom(src => src.WorkEvent.Date)) //属性匹配匹配源类中WorkEvent.Date到EventDate
.ForMember(dest => dest.YAxis, opt => opt.MapFrom(src => src.ConfigChartYAxis))//
.ReverseMap();
}
}
}