Created
February 19, 2013 15:20
-
-
Save Fodsuk/4986794 to your computer and use it in GitHub Desktop.
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 IMappingExpression<TSource, TDestination> IgnoreAllNonExisting<TSource, TDestination>(this IMappingExpression<TSource, TDestination> expression) | |
{ | |
var sourceType = typeof(TSource); | |
var destinationType = typeof(TDestination); | |
var existingMaps = Mapper.GetAllTypeMaps(); | |
var first = existingMaps.First(x => x.SourceType == sourceType && x.DestinationType == destinationType); | |
foreach (var property in first.GetUnmappedPropertyNames()) | |
{ | |
expression.ForMember(property, opt => opt.Ignore()); | |
} | |
return expression; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment