1- using System ;
1+ using Mapster . Models ;
2+ using System ;
23using System . Collections . Generic ;
4+ using System . Data ;
35using System . Linq ;
46using System . Reflection ;
5- using Mapster . Models ;
67
78namespace Mapster
89{
@@ -38,6 +39,14 @@ public static TDestination Adapt<TDestination>(this object? source)
3839 /// <returns>Adapted destination type.</returns>
3940 public static TDestination Adapt < TDestination > ( this object ? source , TypeAdapterConfig config )
4041 {
42+ if ( config . RuleMap . TryGetValue ( new TypeTuple ( source . GetType ( ) , typeof ( TDestination ) ) , out var rule ) )
43+ {
44+ if ( rule . Settings . InheritsTypeTuples . Count > 0 )
45+ {
46+ LoadInheritedRules ( config , rule , rule . Settings . InheritsTypeTuples ) ;
47+ }
48+ }
49+
4150 // ReSharper disable once ConditionIsAlwaysTrueOrFalse
4251 if ( source == null )
4352 return default ! ;
@@ -46,6 +55,22 @@ public static TDestination Adapt<TDestination>(this object? source, TypeAdapterC
4655 return fn ( source ) ;
4756 }
4857
58+ private static void LoadInheritedRules ( TypeAdapterConfig config , TypeAdapterRule rule , IEnumerable < InheritsTypeTuple > inheritedTypes )
59+ {
60+ foreach ( var typeTuple in inheritedTypes . Where ( t => ! t . IsLoading ) )
61+ {
62+ if ( config . RuleMap . TryGetValue ( new TypeTuple ( typeTuple . Source , typeTuple . Destination ) , out var parentRule ) )
63+ {
64+ rule . LoadLasyInherits ( parentRule ) ;
65+ typeTuple . IsUploaded ( ) ;
66+ }
67+ if ( parentRule != null && parentRule . Settings . InheritsTypeTuples . Any ( ) )
68+ {
69+ LoadInheritedRules ( config , rule , parentRule . Settings . InheritsTypeTuples ) ;
70+ }
71+ }
72+ }
73+
4974 /// <summary>
5075 /// Adapt the source object to the destination type.
5176 /// </summary>
@@ -254,7 +279,7 @@ public static TDestination ValidateAndAdapt<TSource, TDestination>(this TSource
254279 }
255280 return source . Adapt < TDestination > ( config ) ;
256281 }
257- }
282+ }
258283
259284 [ System . Diagnostics . CodeAnalysis . SuppressMessage ( "Minor Code Smell" , "S1104:Fields should not have public accessibility" , Justification = "<Pending>" ) ]
260285 public static class TypeAdapter < TSource , TDestination >
0 commit comments