File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed
Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change 1- using System ;
1+ using System ;
22using System . Collections . Generic ;
3+ using System . Diagnostics . CodeAnalysis ;
34using System . Linq ;
45using System . Reflection ;
56using Mapster . Models ;
@@ -24,7 +25,8 @@ public static ITypeAdapterBuilder<TSource> BuildAdapter<TSource>(this TSource so
2425 /// <typeparam name="TDestination">Destination type.</typeparam>
2526 /// <param name="source">Source object to adapt.</param>
2627 /// <returns>Adapted destination type.</returns>
27- public static TDestination Adapt < TDestination > ( this object ? source )
28+ [ return : NotNullIfNotNull ( nameof ( source ) ) ]
29+ public static TDestination ? Adapt < TDestination > ( this object ? source )
2830 {
2931 return Adapt < TDestination > ( source , TypeAdapterConfig . GlobalSettings ) ;
3032 }
@@ -36,14 +38,15 @@ public static TDestination Adapt<TDestination>(this object? source)
3638 /// <param name="source">Source object to adapt.</param>
3739 /// <param name="config">Configuration</param>
3840 /// <returns>Adapted destination type.</returns>
39- public static TDestination Adapt < TDestination > ( this object ? source , TypeAdapterConfig config )
41+ [ return : NotNullIfNotNull ( nameof ( source ) ) ]
42+ public static TDestination ? Adapt < TDestination > ( this object ? source , TypeAdapterConfig config )
4043 {
4144 // ReSharper disable once ConditionIsAlwaysTrueOrFalse
4245 if ( source == null )
43- return default ! ;
46+ return default ;
4447 var type = source . GetType ( ) ;
4548 var fn = config . GetDynamicMapFunction < TDestination > ( type ) ;
46- return fn ( source ) ;
49+ return fn ( source ) ! ;
4750 }
4851
4952 /// <summary>
You can’t perform that action at this time.
0 commit comments