Skip to content

Instantly share code, notes, and snippets.

@aaronbarnaby
Created April 6, 2021 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronbarnaby/2f2b17466c2a653f0332c8f8a578080e to your computer and use it in GitHub Desktop.
Save aaronbarnaby/2f2b17466c2a653f0332c8f8a578080e to your computer and use it in GitHub Desktop.
Mapping Extension class for handling multiple sources to destination.
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