DD.WellWorkover.Cloud/AsbCloudInfrastructure/MapsterExtension.cs
Фролов 30a59d0809 cleanup
2021-09-10 11:28:57 +05:00

44 lines
1.4 KiB
C#

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