using AutoMapper;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
|
namespace IStation
|
{
|
/// <summary>
|
/// AutoMapper帮助类
|
/// </summary>
|
public static class AutoMapperHelper
|
{
|
/// <summary>
|
/// 映射单项
|
/// </summary>
|
public static Out MapTo<In, Out>(this In obj)
|
{
|
var mapper = new MapperConfiguration(cfg => cfg.CreateMap<In, Out>()).CreateMapper();
|
return mapper.Map<In, Out>(obj);
|
}
|
|
/// <summary>
|
/// 映射单项
|
/// </summary>
|
public static void Map<In, Out>(this In inner, Out outer)
|
{
|
var mapper = new MapperConfiguration(cfg => cfg.CreateMap<In, Out>()).CreateMapper();
|
mapper.Map(inner, outer);
|
}
|
|
/// <summary>
|
/// 映射集合
|
/// </summary>
|
public static List<Out> MapTo<In, Out>(this IEnumerable<In> objs)
|
{
|
var mapper = new MapperConfiguration(cfg => cfg.CreateMap<In, Out>()).CreateMapper();
|
return mapper.Map<IEnumerable<In>, List<Out>>(objs);
|
}
|
|
/// <summary>
|
/// 映射集合
|
/// </summary>
|
public static void Map<In, Out>(this IEnumerable<In> inners, IEnumerable<Out> outers)
|
{
|
var mapper = new MapperConfiguration(cfg => cfg.CreateMap<In, Out>()).CreateMapper();
|
mapper.Map(inners, outers);
|
}
|
|
}
|
}
|