@@ -317,12 +317,41 @@ public Func<TSource, TDestination> GetMapFunction<TSource, TDestination>()
317317 }
318318 internal Delegate GetMapFunction ( Type sourceType , Type destinationType )
319319 {
320+ LoadInheritedRulesLazy ( new TypeTuple ( sourceType , destinationType ) ) ;
321+
320322 var key = new TypeTuple ( sourceType , destinationType ) ;
321323 if ( ! _mapDict . TryGetValue ( key , out var del ) )
322324 del = AddToHash ( _mapDict , key , tuple => Compiler ( CreateMapExpression ( tuple , MapType . Map ) ) ) ;
323325 return del ;
324326 }
325327
328+ private void LoadInheritedRulesLazy ( TypeTuple types )
329+ {
330+ if ( RuleMap . TryGetValue ( types , out var rule ) )
331+ {
332+ if ( rule . Settings . InheritsTypeTuples . Count > 0 )
333+ {
334+ LoadInheritedRules ( rule , rule . Settings . InheritsTypeTuples ) ;
335+ }
336+ }
337+ }
338+ private void LoadInheritedRules ( TypeAdapterRule rule , IEnumerable < InheritsTypeTuple > inheritedTypes )
339+ {
340+ foreach ( var typeTuple in inheritedTypes . Where ( t => ! t . IsLoading ) )
341+ {
342+ if ( RuleMap . TryGetValue ( new TypeTuple ( typeTuple . Source , typeTuple . Destination ) , out var parentRule ) )
343+ {
344+ rule . LoadLasyInherits ( parentRule ) ;
345+ typeTuple . IsUploaded ( ) ;
346+ }
347+ if ( parentRule != null && parentRule . Settings . InheritsTypeTuples . Any ( ) )
348+ {
349+ LoadInheritedRules ( rule , parentRule . Settings . InheritsTypeTuples ) ;
350+ }
351+ }
352+ }
353+
354+
326355 private readonly ConcurrentDictionary < TypeTuple , Delegate > _mapToTargetDict = new ConcurrentDictionary < TypeTuple , Delegate > ( ) ;
327356 public Func < TSource , TDestination , TDestination > GetMapToTargetFunction < TSource , TDestination > ( )
328357 {
@@ -331,6 +360,9 @@ public Func<TSource, TDestination, TDestination> GetMapToTargetFunction<TSource,
331360 internal Delegate GetMapToTargetFunction ( Type sourceType , Type destinationType )
332361 {
333362 var key = new TypeTuple ( sourceType , destinationType ) ;
363+
364+ LoadInheritedRulesLazy ( key ) ;
365+
334366 if ( ! _mapToTargetDict . TryGetValue ( key , out var del ) )
335367 del = AddToHash ( _mapToTargetDict , key , tuple => Compiler ( CreateMapExpression ( tuple , MapType . MapToTarget ) ) ) ;
336368 return del ;
@@ -346,6 +378,9 @@ internal Expression<Func<TSource, TDestination>> GetProjectionExpression<TSource
346378 internal MethodCallExpression GetProjectionCallExpression ( Type sourceType , Type destinationType )
347379 {
348380 var key = new TypeTuple ( sourceType , destinationType ) ;
381+
382+ LoadInheritedRulesLazy ( key ) ;
383+
349384 if ( ! _projectionDict . TryGetValue ( key , out var del ) )
350385 del = AddToHash ( _projectionDict , key , CreateProjectionCallExpression ) ;
351386 return del ;
@@ -355,6 +390,9 @@ internal MethodCallExpression GetProjectionCallExpression(Type sourceType, Type
355390 public Func < object , TDestination > GetDynamicMapFunction < TDestination > ( Type sourceType )
356391 {
357392 var key = new TypeTuple ( sourceType , typeof ( TDestination ) ) ;
393+
394+ LoadInheritedRulesLazy ( key ) ;
395+
358396 if ( ! _dynamicMapDict . TryGetValue ( key , out var del ) )
359397 del = AddToHash ( _dynamicMapDict , key , tuple => Compiler ( CreateDynamicMapExpression ( tuple ) ) ) ;
360398 return ( Func < object , TDestination > ) del ;
0 commit comments