Last active
April 7, 2016 21:17
-
-
Save kmorcinek/64641a11a4cd5b8c18d8 to your computer and use it in GitHub Desktop.
AutoMapper convenient extensions for simple mapping
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 AutoMapperExtensions | |
{ | |
/// <summary> | |
/// Maps properties as ignored. | |
/// </summary> | |
public static IMappingExpression<TSource, TDestination> Ignore<TSource, TDestination>( | |
this IMappingExpression<TSource, TDestination> map, | |
Expression<Func<TDestination, object>> selector) | |
{ | |
map.ForMember(selector, config => config.Ignore()); | |
return map; | |
} | |
/// <summary> | |
/// Sets mapping from source property to destination property. Convenient extension method. | |
/// </summary> | |
public static IMappingExpression<TSource, TDestination> MapProperty<TSource, TDestination, TProperty>( | |
this IMappingExpression<TSource, TDestination> map, | |
Expression<Func<TSource, TProperty>> sourceMember, | |
Expression<Func<TDestination, object>> targetMember) | |
{ | |
map.ForMember(targetMember, opt => opt.MapFrom(sourceMember)); | |
return map; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment