DD.WellWorkover.Cloud/AsbCloudInfrastructure/MapsterExtension.cs

41 lines
1.3 KiB
C#
Raw Normal View History

2021-07-28 09:46:58 +05:00
using System;
using System.Collections.Generic;
using System.Linq;
2021-07-28 09:46:58 +05:00
namespace Mapster
{
public static class MapsterExtension
{
public static IEnumerable<TDestination> Adapt<TDestination>(this IEnumerable<object> sourceList)
{
return sourceList.Select(item => item.Adapt<TDestination>());
2021-07-28 09:46:58 +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>();
afterMapAction?.Invoke(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>();
afterMapAction?.Invoke(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>();
eachAfterMapAction?.Invoke(dest, item);
yield return dest;
}
2021-09-10 11:28:57 +05:00
2021-07-28 09:46:58 +05:00
}
}
}