Created
April 6, 2021 12:34
-
-
Save aaronbarnaby/2f2b17466c2a653f0332c8f8a578080e to your computer and use it in GitHub Desktop.
Mapping Extension class for handling multiple sources to destination.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class MappingExtentions | |
{ | |
public static TDestination Map<TDestination>(this IMapper mapper, params object[] sources) where TDestination : new() | |
{ | |
return Map(mapper, new TDestination(), sources); | |
} | |
public static TDestination Map<TDestination>(this IMapper mapper, TDestination destination, params object[] sources) where TDestination : new() | |
{ | |
if (!sources.Any()) | |
return destination; | |
foreach (var src in sources) | |
destination = mapper.Map(src, destination); | |
return destination; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment