Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AutoMapper convenient extensions for simple mapping
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
You can’t perform that action at this time.