public virtual Expression GenerateExcludeAction(Type sourceType, Type targetType, ParameterExpression sourcePar, ParameterExpression targetPar, MemberInitExpression mie) { Dictionary <MemberInfo, Expression> dic = new Dictionary <MemberInfo, Expression>(); foreach (var m in mie.Bindings) { if (m is MemberAssignment ma) { dic.Add(ma.Member, ma.Expression); } } MethodInfo pmi = _provider.GetType().GetMethod("GetMapper"); pmi = pmi.MakeGenericMethod(sourceType, targetType); var mapperType = typeof(IMapper <,>).MakeGenericType(sourceType, targetType); ParameterExpression mapperVar = ParameterExpression.Variable(mapperType); var mmaper = Expression.Assign(mapperVar, Expression.Call( Expression.Constant(_provider), pmi)); MethodInfo mi = mapperType.GetMethod("GenerateDefaultCopyToDelegateWithExclude", BindingFlags.Public | BindingFlags.Instance); var actionType = typeof(Action <,>).MakeGenericType(sourceType, targetType); var actionVar = Expression.Variable(actionType); var action = Expression.Assign( actionVar, Expression.Call(mapperVar, mi, Expression.Constant(dic))); var invoke = Expression.Invoke(actionVar, sourcePar, targetPar); return(Expression.Block( new ParameterExpression[] { mapperVar, actionVar }, mmaper, action, invoke )); }