Skip to content

Commit 0933e5c

Browse files
committed
fix null
1 parent 3dbd6b5 commit 0933e5c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/Mapster/TypeAdapter.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public static TDestination Adapt<TDestination>(this object? source)
3939
/// <returns>Adapted destination type.</returns>
4040
public static TDestination Adapt<TDestination>(this object? source, TypeAdapterConfig config)
4141
{
42+
if (source == null)
43+
return default!;
44+
4245
if (config.RuleMap.TryGetValue(new TypeTuple(source.GetType(), typeof(TDestination)), out var rule))
4346
{
4447
if (rule.Settings.InheritsTypeTuples.Count > 0)
@@ -48,8 +51,7 @@ public static TDestination Adapt<TDestination>(this object? source, TypeAdapterC
4851
}
4952

5053
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
51-
if (source == null)
52-
return default!;
54+
5355
var type = source.GetType();
5456
var fn = config.GetDynamicMapFunction<TDestination>(type);
5557
return fn(source);

0 commit comments

Comments
 (0)