Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/Mapster/TypeAdapter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using Mapster.Models;
Expand All @@ -24,7 +25,8 @@ public static ITypeAdapterBuilder<TSource> BuildAdapter<TSource>(this TSource so
/// <typeparam name="TDestination">Destination type.</typeparam>
/// <param name="source">Source object to adapt.</param>
/// <returns>Adapted destination type.</returns>
public static TDestination Adapt<TDestination>(this object? source)
[return: NotNullIfNotNull(nameof(source))]
public static TDestination? Adapt<TDestination>(this object? source)
{
return Adapt<TDestination>(source, TypeAdapterConfig.GlobalSettings);
}
Expand All @@ -36,14 +38,15 @@ public static TDestination Adapt<TDestination>(this object? source)
/// <param name="source">Source object to adapt.</param>
/// <param name="config">Configuration</param>
/// <returns>Adapted destination type.</returns>
public static TDestination Adapt<TDestination>(this object? source, TypeAdapterConfig config)
[return: NotNullIfNotNull(nameof(source))]
public static TDestination? Adapt<TDestination>(this object? source, TypeAdapterConfig config)
{
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
if (source == null)
return default!;
return default;
var type = source.GetType();
var fn = config.GetDynamicMapFunction<TDestination>(type);
return fn(source);
return fn(source)!;
}

/// <summary>
Expand Down
Loading