DD.WellWorkover.Cloud/AsbCloudInfrastructure/MapsterExtension.cs
2021-12-07 18:27:52 +05:00

41 lines
1.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
namespace Mapster
{
public static class MapsterExtension
{
public static IEnumerable<TDestination> Adapt<TDestination>(this IEnumerable<object> sourceList)
{
return sourceList.Select(item => item.Adapt<TDestination>());
}
public static TDestination Adapt<TDestination>(this object source, Action<TDestination> afterMapAction = default)
{
var dest = source.Adapt<TDestination>();
afterMapAction?.Invoke(dest);
return dest;
}
public static TDestination Adapt<TDestination, TSource>(this TSource source, Action<TDestination, TSource> afterMapAction = default)
{
var dest = source.Adapt<TDestination>();
afterMapAction?.Invoke(dest, source);
return dest;
}
public static IEnumerable<TDestination> Adapt<TDestination, TSource>(this IEnumerable<TSource> sourceList, Action<TDestination, TSource> eachAfterMapAction = default)
{
foreach (var item in sourceList)
{
var dest = item.Adapt<TDestination>();
eachAfterMapAction?.Invoke(dest, item);
yield return dest;
}
}
}
}