41 lines
1.3 KiB
C#
41 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Linq.Expressions;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using AutoMapper;
|
|
using Server.Utils;
|
|
|
|
namespace Server
|
|
{
|
|
/// <summary>
|
|
/// 扩展
|
|
/// </summary>
|
|
public static class AutoMapperEx
|
|
{
|
|
/// <summary>
|
|
/// 绑定指定名字
|
|
/// </summary>
|
|
/// <typeparam name="TSource"></typeparam>
|
|
/// <typeparam name="TDestination"></typeparam>
|
|
/// <typeparam name="TMember"></typeparam>
|
|
/// <param name="c"></param>
|
|
/// <param name="memberName"></param>
|
|
public static void MapFromDynamic<TSource, TDestination, TMember>(
|
|
this IMemberConfigurationExpression<TSource, TDestination, TMember> c, string memberName, Func<object, TMember> resolverValue = null)
|
|
{
|
|
var resolver = new DynamicCustomResolver<TSource, TDestination, TMember>(memberName.Trim(' '), resolverValue);
|
|
c.MapFrom(resolver);
|
|
}
|
|
|
|
public static IMappingExpression<TSource, TDestination> Ignore<TSource, TDestination>(
|
|
this IMappingExpression<TSource, TDestination> map,
|
|
Expression<Func<TDestination, object>> selector)
|
|
{
|
|
map.ForMember(selector, config => config.Ignore());
|
|
return map;
|
|
}
|
|
}
|
|
}
|