track/src/SJZY.Track.Application/AutoMapper/AutoMapperProfile.cs
2024-03-01 10:14:49 +08:00

33 lines
1.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

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 SJZY.Track.Application.Contract.Dtos.Demo;
using SJZY.Track.Domain.Aggregates.DemoAggregate;
using SJZY.Track.Domain.Dtos.Demo;
namespace SJZY.Track.Application.AutoMapper;
internal class AutoMapperProfile : Profile
{
public AutoMapperProfile()
{
CreateMap<UnifyPageResultDto<DemoEntity>, UnifyPageResultDto<GetDemoListByPageOutput>>(MemberList.None);
CreateMap<GetDemoListByPageInput, DemoValueObject>(MemberList.None).ReverseMap();
CreateMap<UnifyPageResultDto<GetDemoListByPageInput>, UnifyPageResultDto<DemoValueObject>>(MemberList.None)
.ReverseMap();
/*
代码说明:
MemberList.None的意思是,忽略源对象和目标对象的属性匹配检查,其他可选值:MemberList.Source(检查是否映射了所有源成员)、MemberList.Destination(检查是否映射了所有目标成员)
.ReverseMap()的意思是配置双向调用关系,既一行代码既支持从 GetDemoListByPageInput -> DemoValueObject 的映射,同时也支持从 DemoValueObject -> GetDemoListByPageInput 的映射
如果对一对模型多次配置规则,会以最后一次为准,配置了这样规则后,最终执行结果是 Name + 444
CreateMap<DemoInput, DemoEntity>().ForMember(dest => dest.Description, opt => opt.MapFrom(m => m.Name + "22"));
CreateMap<DemoInput, DemoEntity>().ForMember(dest => dest.Description, opt => opt.MapFrom(m => m.Name + "444"));
*/
CreateMap<DemoEntity, DemoInput>(MemberList.None).ReverseMap();
CreateMap<DemoEntity, GetDemoListByPageOutput>(MemberList.None);
CreateMap<DemoEntity, DemoDetailSaveInput>(MemberList.None).ReverseMap();
}
}