new API project

This commit is contained in:
2021-11-29 18:25:50 +01:00
parent 192a0d795a
commit 346a674306
85 changed files with 940 additions and 410 deletions
+50
View File
@@ -0,0 +1,50 @@
namespace zero.Mapper;
public static class MapperExtensions
{
//public static TDestination Register<TSource, TDestination>(this IZeroMapper mapper, Action<TSource, TDestination, IZeroMapperContext> map) where TDestination : class, new()
//{
//}
//public static TDestination Register<TSource, TDestination>(this IZeroMapper mapper, Action<TSource, TDestination, IZeroMapperContext> map, TDestination destination)
//{
//}
public static TDestination Map<TSource, TDestination>(this IZeroMapper mapper, TSource source, TDestination destination)
{
return mapper.Map(source, typeof(TSource), destination);
}
public static TDestination Map<TSource, TDestination>(this IZeroMapper mapper, TSource source)
{
return mapper.Map<TDestination>(source, typeof(TSource), default);
}
public static Paged<TDestination> Map<TSource, TDestination>(this IZeroMapper mapper, Paged<TSource> source)
{
return source.MapTo(srcItem => mapper.Map<TSource, TDestination>(srcItem));
}
public static Result<TDestination> Map<TSource, TDestination>(this IZeroMapper mapper, Result<TSource> source)
{
TDestination model = mapper.Map<TSource, TDestination>(source.Model);
return source.ConvertTo(model);
}
public static Dictionary<string, TDestination> Map<TSource, TDestination>(this IZeroMapper mapper, Dictionary<string, TSource> source)
{
Dictionary<string, TDestination> model = new();
foreach ((string key, TSource sourceItem) in source)
{
model.Add(key, sourceItem == null ? default : mapper.Map<TSource, TDestination>(sourceItem));
}
return model;
}
}