Skip to content
Merged
Show file tree
Hide file tree
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
41 changes: 11 additions & 30 deletions src/Mapster/Adapters/BaseAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,32 +85,6 @@ protected virtual Expression CreateExpressionBody(Expression source, Expression?
if (CheckExplicitMapping && arg.Context.Config.RequireExplicitMapping && !arg.ExplicitMapping)
throw new InvalidOperationException("Implicit mapping is not allowed (check GlobalSettings.RequireExplicitMapping) and no configuration exists");

#region CustomMappingPrimitiveImplimentation

if (arg.Settings.MapToTargetPrimitive == true)
{
Expression dest;

if (destination == null)
{
dest = arg.DestinationType.CreateDefault();
}
else
dest = destination;

var customConvert = arg.Context.Config.CreateMapToTargetInvokeExpressionBody(source.Type, arg.DestinationType, source, dest);

arg.MapType = MapType.MapToTarget;
return customConvert;
}

if (arg.Settings.MapWithToPrimitive == true)
{
return arg.Context.Config.CreateMapInvokeExpressionBody(source.Type, arg.DestinationType, source);
}

#endregion CustomMappingPrimitiveImplimentation

var oldMaxDepth = arg.Context.MaxDepth;
var oldDepth = arg.Context.Depth;
try
Expand All @@ -128,11 +102,18 @@ protected virtual Expression CreateExpressionBody(Expression source, Expression?
arg.Context.Depth++;
}

if (CanInline(source, destination, arg))
if(arg.Settings.MapToTargetPrimitive == true)
{
// skip inline mapping
}
else
{
var exp = CreateInlineExpressionBody(source, arg);
if (exp != null)
return exp.To(arg.DestinationType, true);
if (CanInline(source, destination, arg))
{
var exp = CreateInlineExpressionBody(source, arg);
if (exp != null)
return exp.To(arg.DestinationType, true);
}
}

if (arg.Context.Running.Count > 1 &&
Expand Down
5 changes: 0 additions & 5 deletions src/Mapster/TypeAdapterSetter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -612,11 +612,6 @@ public TypeAdapterSetter<TSource, TDestination> MapWith(Expression<Func<TSource,
{
this.CheckCompiled();

if(typeof(TSource).IsMapsterPrimitive() || typeof(TDestination).IsMapsterPrimitive())
{
this.Settings.MapWithToPrimitive = true;
}

if (applySettings)
{
var adapter = new DelegateAdapter(converterFactory);
Expand Down
6 changes: 0 additions & 6 deletions src/Mapster/TypeAdapterSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,6 @@ public object? GenerateMapper
set => Set(nameof(GenerateMapper), value);
}

public bool? MapWithToPrimitive
{
get => Get(nameof(MapWithToPrimitive));
set => Set(nameof(MapWithToPrimitive), value);
}

/// <summary>
/// Not implemented
/// </summary>
Expand Down
Loading