@@ -38,11 +38,7 @@ public static void RegisterConverter<From, To>(Func<From, To> converter)
3838 converters [ Tuple . Create ( typeof ( From ) , typeof ( To ) ) ] = x => converter ( ( From ) x ) ;
3939 }
4040
41- public static void IgnoreMapping < From , To > ( )
42- {
43- JsConfig . InitStatics ( ) ;
44- ignoreMappings [ Tuple . Create ( typeof ( From ) , typeof ( To ) ) ] = true ;
45- }
41+ public static void IgnoreMapping < From , To > ( ) => IgnoreMapping ( typeof ( From ) , typeof ( To ) ) ;
4642
4743 public static void IgnoreMapping ( Type fromType , Type toType )
4844 {
@@ -108,6 +104,9 @@ public static object ConvertTo(this object from, Type toType, bool skipConverter
108104 if ( fromType == toType )
109105 return from ;
110106
107+ if ( ShouldIgnoreMapping ( fromType , toType ) )
108+ return null ;
109+
111110 if ( ! skipConverters )
112111 {
113112 var converter = GetConverter ( fromType , toType ) ;
@@ -781,6 +780,29 @@ public void AddMatch(string name, AssignmentMember readMember, AssignmentMember
781780 if ( AutoMappingUtils . ShouldIgnoreMapping ( readMember . Type , writeMember . Type ) )
782781 return ;
783782
783+ // Ignore mapping collections if Element Types are ignored
784+ if ( typeof ( IEnumerable ) . IsAssignableFrom ( readMember . Type ) && typeof ( IEnumerable ) . IsAssignableFrom ( writeMember . Type ) )
785+ {
786+ var fromGenericDef = readMember . Type . GetTypeWithGenericTypeDefinitionOf ( typeof ( IDictionary < , > ) ) ;
787+ var toGenericDef = readMember . Type . GetTypeWithGenericTypeDefinitionOf ( typeof ( IDictionary < , > ) ) ;
788+ if ( fromGenericDef != null && toGenericDef != null )
789+ {
790+ // Check if to/from Key or Value Types are ignored
791+ if ( AutoMappingUtils . ShouldIgnoreMapping ( fromGenericDef . GetGenericArguments ( ) [ 0 ] , toGenericDef . GetGenericArguments ( ) [ 0 ] ) )
792+ return ;
793+ if ( AutoMappingUtils . ShouldIgnoreMapping ( fromGenericDef . GetGenericArguments ( ) [ 1 ] , toGenericDef . GetGenericArguments ( ) [ 1 ] ) )
794+ return ;
795+ }
796+ else if ( readMember . Type != typeof ( string ) && writeMember . Type != typeof ( string ) )
797+ {
798+ var elFromType = readMember . Type . GetCollectionType ( ) ;
799+ var elToType = writeMember . Type . GetCollectionType ( ) ;
800+
801+ if ( AutoMappingUtils . ShouldIgnoreMapping ( elFromType , elToType ) )
802+ return ;
803+ }
804+ }
805+
784806 this . AssignmentMemberMap [ name ] = new AssignmentEntry ( name , readMember , writeMember ) ;
785807 }
786808
0 commit comments