automapper (1)


Ignore all non exisisting properties with Automapper

Code Snippet public static class MappingCustomExtension {     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().First(x => x.SourceType.Equals(sourceType) && x.DestinationType.Equals(destinationType));         foreach (var property in existingMaps.GetUnmappedPropertyNames())         {             expression.ForMember(property, opt => opt.Ignore());         }         return expression;     } }