From ecb87a3309751081256fabe57f99e964b4f2e050 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?SAL=C4=B0H=20=C3=96ZKARA?= Date: Tue, 9 Sep 2025 14:14:11 +0300 Subject: [PATCH] Fix ExtraProperties dictionary reference handling in mapping --- .../MapperlyAutoObjectMappingProvider.cs | 29 ++++++++++++------- ...raProperties_Dictionary_Reference_Tests.cs | 3 ++ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/framework/src/Volo.Abp.Mapperly/Volo/Abp/Mapperly/MapperlyAutoObjectMappingProvider.cs b/framework/src/Volo.Abp.Mapperly/Volo/Abp/Mapperly/MapperlyAutoObjectMappingProvider.cs index f6a0de2d30..3876ee09a1 100644 --- a/framework/src/Volo.Abp.Mapperly/Volo/Abp/Mapperly/MapperlyAutoObjectMappingProvider.cs +++ b/framework/src/Volo.Abp.Mapperly/Volo/Abp/Mapperly/MapperlyAutoObjectMappingProvider.cs @@ -46,7 +46,7 @@ public class MapperlyAutoObjectMappingProvider : IAutoObjectMappingProvider { mapper.BeforeMap((TSource)source); var destination = mapper.Map((TSource)source); - TryMapExtraProperties(mapper.GetType().GetSingleAttributeOrNull(), (TSource)source, destination, new ExtraPropertyDictionary()); + TryMapExtraProperties(mapper.GetType().GetSingleAttributeOrNull(), (TSource)source, destination, GetExtraProperties(destination)); mapper.AfterMap((TSource)source, destination); return destination; } @@ -245,15 +245,24 @@ public class MapperlyAutoObjectMappingProvider : IAutoObjectMappingProvider { return; } - - MapExtraProperties( - sourceHasExtraProperties, - destinationHasExtraProperties, - destinationExtraProperty, - mapExtraPropertiesAttribute?.DefinitionChecks ?? MappingPropertyDefinitionChecks.Null, - mapExtraPropertiesAttribute?.IgnoredProperties, - mapExtraPropertiesAttribute?.MapToRegularProperties ?? false - ); + + if (sourceHasExtraProperties.ExtraProperties != null && sourceHasExtraProperties.ExtraProperties == + destinationHasExtraProperties.ExtraProperties) + { + ObjectHelper.TrySetProperty(destinationHasExtraProperties, x => x.ExtraProperties, () => new ExtraPropertyDictionary(destinationHasExtraProperties.ExtraProperties));; + } + + if (mapExtraPropertiesAttribute != null) + { + MapExtraProperties( + sourceHasExtraProperties, + destinationHasExtraProperties, + destinationExtraProperty, + mapExtraPropertiesAttribute.DefinitionChecks, + mapExtraPropertiesAttribute.IgnoredProperties, + mapExtraPropertiesAttribute.MapToRegularProperties + ); + } } protected virtual void MapExtraProperties( IHasExtraProperties source, diff --git a/framework/test/Volo.Abp.Mapperly.Tests/Volo/Abp/Mapperly/ExtraProperties_Dictionary_Reference_Tests.cs b/framework/test/Volo.Abp.Mapperly.Tests/Volo/Abp/Mapperly/ExtraProperties_Dictionary_Reference_Tests.cs index 19bc24904e..e5453d09a3 100644 --- a/framework/test/Volo.Abp.Mapperly.Tests/Volo/Abp/Mapperly/ExtraProperties_Dictionary_Reference_Tests.cs +++ b/framework/test/Volo.Abp.Mapperly.Tests/Volo/Abp/Mapperly/ExtraProperties_Dictionary_Reference_Tests.cs @@ -96,6 +96,9 @@ public class ExtraProperties_Dictionary_Reference_Tests : AbpIntegratedTest