2021-07-28 09:46:58 +05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace Mapster
|
|
|
|
|
{
|
|
|
|
|
public static class MapsterExtension
|
|
|
|
|
{
|
|
|
|
|
public static IEnumerable<TDestination> Adapt<TDestination>(this IEnumerable<object> sourceList)
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in sourceList)
|
|
|
|
|
yield return item.Adapt<TDestination>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-08-27 12:15:04 +05:00
|
|
|
|
public static TDestination Adapt<TDestination>(this object source, Action<TDestination> afterMapAction = default)
|
2021-07-28 09:46:58 +05:00
|
|
|
|
{
|
|
|
|
|
var dest = source.Adapt<TDestination>();
|
|
|
|
|
if (afterMapAction != default)
|
2021-08-27 12:15:04 +05:00
|
|
|
|
afterMapAction(dest);
|
2021-07-28 09:46:58 +05:00
|
|
|
|
return dest;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-27 12:15:04 +05:00
|
|
|
|
public static TDestination Adapt<TDestination, TSource>(this TSource source, Action<TDestination, TSource> afterMapAction = default)
|
|
|
|
|
{
|
|
|
|
|
var dest = source.Adapt<TDestination>();
|
|
|
|
|
if (afterMapAction != default)
|
|
|
|
|
afterMapAction(dest, source);
|
|
|
|
|
return dest;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static IEnumerable<TDestination> Adapt<TDestination, TSource>(this IEnumerable<TSource> sourceList, Action<TDestination, TSource> eachAfterMapAction = default)
|
2021-07-28 09:46:58 +05:00
|
|
|
|
{
|
|
|
|
|
foreach (var item in sourceList)
|
2021-08-27 12:15:04 +05:00
|
|
|
|
{
|
|
|
|
|
var dest = item.Adapt<TDestination>();
|
|
|
|
|
if (eachAfterMapAction != default)
|
|
|
|
|
eachAfterMapAction(dest, item);
|
|
|
|
|
yield return dest;
|
|
|
|
|
}
|
2021-09-10 11:28:57 +05:00
|
|
|
|
|
2021-07-28 09:46:58 +05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|