DD.WellWorkover.Cloud/AsbCloudInfrastructure/MapsterExtension.cs

44 lines
1.4 KiB
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<TDestination>(this object source, Action<TDestination> afterMapAction = default)
2021-07-28 09:46:58 +05:00
{
var dest = source.Adapt<TDestination>();
if (afterMapAction != default)
afterMapAction(dest);
2021-07-28 09:46:58 +05:00
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)
2021-07-28 09:46:58 +05:00
{
foreach (var item in sourceList)
{
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
}
}
}