@@ -126,7 +126,8 @@ public static bool TargetMemberEverRecurses(this IMemberMapperData mapperData)
126126 // the RecursionMapperFunc which performs the recursive mapping:
127127 return TargetMemberIsRecursionWithin (
128128 parentMapperData . TargetMember ,
129- mapperData . TargetMember . LeafMember ) ;
129+ mapperData . TargetMember . LeafMember ,
130+ new List < Type > ( ) ) ;
130131 }
131132
132133 parentMapperData = parentMapperData . Parent ;
@@ -135,7 +136,10 @@ public static bool TargetMemberEverRecurses(this IMemberMapperData mapperData)
135136 return false ;
136137 }
137138
138- private static bool TargetMemberIsRecursionWithin ( QualifiedMember parentMember , Member member )
139+ private static bool TargetMemberIsRecursionWithin (
140+ QualifiedMember parentMember ,
141+ Member member ,
142+ ICollection < Type > checkedTypes )
139143 {
140144 while ( true )
141145 {
@@ -148,7 +152,7 @@ private static bool TargetMemberIsRecursionWithin(QualifiedMember parentMember,
148152 var nonSimpleChildMembers = GlobalContext . Instance
149153 . MemberFinder
150154 . GetTargetMembers ( parentMember . Type )
151- . Where ( m => ! m . IsSimple )
155+ . Where ( m => ! m . IsSimple && ! checkedTypes . Contains ( m . IsEnumerable ? m . ElementType : m . Type ) )
152156 . ToArray ( ) ;
153157
154158 if ( nonSimpleChildMembers . None ( ) )
@@ -165,7 +169,10 @@ private static bool TargetMemberIsRecursionWithin(QualifiedMember parentMember,
165169 return childMember . IsRecursion ;
166170 }
167171
168- return nonSimpleChildMembers . Any ( m => TargetMemberIsRecursionWithin ( parentMember . Append ( m ) , member ) ) ;
172+ checkedTypes . Add ( parentMember . Type ) ;
173+
174+ return nonSimpleChildMembers . Any ( m =>
175+ TargetMemberIsRecursionWithin ( parentMember . Append ( m ) , member , checkedTypes ) ) ;
169176 }
170177 }
171178
@@ -375,6 +382,7 @@ private static Expression GetAccess(
375382 . MakeGenericType ( contextTypes [ 0 ] , contextTypes [ 1 ] )
376383 . GetProperty ( propertyName ) ;
377384
385+ // ReSharper disable once AssignNullToNotNullAttribute
378386 return Expression . Property ( contextAccess , property ) ;
379387 }
380388
0 commit comments