This repository has been archived by the owner on Apr 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 318
Osharp 版本更新至3.3.4 Model和Dto如何映射
Jesn edited this page Oct 16, 2015
·
1 revision
Dto命名规则必须是以InputDto结尾,eg:EntityInfoInputDto ,FunctionInputDto
在使用中直接映射 User user = dto.MapTo();
/// <summary>
/// 输入DTO-实体映射配对
/// </summary>
public class InputDtoEntityMapTuple : MapTupleBase<InputDtoTypeFinder, EntityTypeFinder>
{
/// <summary>
/// 重写以定义源类型与目标类型的匹配规则
/// </summary>
/// <param name="sourceType">源类型</param>
/// <param name="targetType">目标类型</param>
/// <returns></returns>
protected override bool IsMatch(Type sourceType, Type targetType)
{
const string end = "InputDto";
return sourceType.Name == targetType.Name + end;
}
/// <summary>
/// 重写以实现映射类型的创建
/// </summary>
/// <param name="sourceType">源类型</param>
/// <param name="targetType">目标类型</param>
protected override void CreateMapper(Type sourceType, Type targetType)
{
Mapper.CreateMap(sourceType, targetType);
}
}
power by @osharp-team (osharp.org)