diff --git a/src/Mapster/Adapters/BaseAdapter.cs b/src/Mapster/Adapters/BaseAdapter.cs index 366f1ee..7019f48 100644 --- a/src/Mapster/Adapters/BaseAdapter.cs +++ b/src/Mapster/Adapters/BaseAdapter.cs @@ -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 @@ -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 && diff --git a/src/Mapster/TypeAdapterSetter.cs b/src/Mapster/TypeAdapterSetter.cs index a058184..7e06d76 100644 --- a/src/Mapster/TypeAdapterSetter.cs +++ b/src/Mapster/TypeAdapterSetter.cs @@ -612,11 +612,6 @@ public TypeAdapterSetter MapWith(Expression Set(nameof(GenerateMapper), value); } - public bool? MapWithToPrimitive - { - get => Get(nameof(MapWithToPrimitive)); - set => Set(nameof(MapWithToPrimitive), value); - } - /// /// Not implemented ///