【后端】.NET Core API框架搭建(11) --对象映射
自定义对象映射。
/// <summary>
/// 描 述:对对象进行转换
/// 标注为notmapped特性时,不转换赋值://[System.ComponentModel.DataAnnotations.Schema.NotMapped]
/// 用法:var newModel = AutoMapper<BaseUseModel, BaseUserEntity>.Map(model);
/// </summary>
public static class AutoMapper<TSource, TTarget> where TSource : class where TTarget : class
{
// 映射委托
public readonly static Func<TSource, TTarget> Map; // 静态构造函数
static AutoMapper()
{
// 初始化映射委托
if (Map == null)
Map = GetMap();
} // 获取映射委托
private static Func<TSource, TTa