Ejemplo n.º 1
0
 /// <summary>
 /// 批量转换
 /// </summary>
 /// <typeparam name="TSource">源类型</typeparam>
 /// <typeparam name="TTarget">目标类型</typeparam>
 /// <param name="source">源对象集合</param>
 /// <returns>转换结果</returns>
 public static IEnumerable <TTarget> Map <TSource, TTarget>(IEnumerable <TSource> source)
 {
     try
     {
         MapperUtil.PreMap(source);
         var target = MapperUtil.MapCores <TSource, TTarget>(source, 0);
         MapperUtil.PostMap(target);
         return(target);
     }
     catch (Exception ex)
     {
         MapperUtil.OnError(ex);
         throw;
     }
     finally
     {
         if (mapperConfig.ReferencePropertyHandle == ReferencePropertyHandle.Loop)
         {
             MapperCache.Clear();
         }
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 转换对象
 /// </summary>
 /// <typeparam name="TSource">源类型</typeparam>
 /// <typeparam name="TTarget">目标类型</typeparam>
 /// <param name="source">源对象</param>
 /// <param name="target">目标对象</param>
 /// <returns>返回转换结果</returns>
 public static TTarget Map <TSource, TTarget>(TSource source, TTarget target = default)
 {
     try
     {
         MapperUtil.PreMap(source);
         target = MapperUtil.MapCore <TSource, TTarget>(source, target, 0);
         MapperUtil.PostMap(target);
         return(target);
     }
     catch (Exception ex)
     {
         MapperUtil.OnError(ex);
         throw;
     }
     finally
     {
         if (mapperConfig.ReferencePropertyHandle == ReferencePropertyHandle.Loop)
         {
             MapperCache.Clear();
         }
     }
 }