DD.WellWorkover.Cloud/AsbCloudInfrastructure/MapsterExtension.cs

30 lines
986 B
C#
Raw Normal View History

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>();
}
public static TDestination Adapt<TSource, TDestination>(this TSource source, Action<TSource, TDestination> afterMapAction = default)
{
var dest = source.Adapt<TDestination>();
if (afterMapAction != default)
afterMapAction(source, dest);
return dest;
}
public static IEnumerable<TDestination> Adapt<TSource, TDestination>(this IEnumerable<TSource> sourceList, Action<TSource, TDestination> eachAfterMapAction = default)
{
foreach (var item in sourceList)
yield return item.Adapt(eachAfterMapAction);
}
}
}