From d8f5012a2b912ed51783eb1be5760145a7545289 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?SAL=C4=B0H=20=C3=96ZKARA?= Date: Tue, 9 Sep 2025 09:28:30 +0300 Subject: [PATCH] Refactor extra properties mapping logic in Mapperly Simplified the logic for mapping extra properties by removing redundant reference checks and always invoking MapExtraProperties with appropriate defaults. Updated related tests and removed unnecessary [MapExtraProperties] attributes from sample mappers. --- .../MapperlyAutoObjectMappingProvider.cs | 32 +++++-------------- ...raProperties_Dictionary_Reference_Tests.cs | 1 - .../Mapperly/SampleClasses/MapperlyMappers.cs | 2 -- 3 files changed, 8 insertions(+), 27 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 c2b830b22f..f6a0de2d30 100644 --- a/framework/src/Volo.Abp.Mapperly/Volo/Abp/Mapperly/MapperlyAutoObjectMappingProvider.cs +++ b/framework/src/Volo.Abp.Mapperly/Volo/Abp/Mapperly/MapperlyAutoObjectMappingProvider.cs @@ -245,31 +245,15 @@ public class MapperlyAutoObjectMappingProvider : IAutoObjectMappingProvider { return; } - - if (sourceHasExtraProperties.ExtraProperties == - destinationHasExtraProperties.ExtraProperties) - { - try - { - ObjectHelper.TrySetProperty(destinationHasExtraProperties, x => x.ExtraProperties, () => new ExtraPropertyDictionary(sourceHasExtraProperties.ExtraProperties)); - } - catch - { - // Has no setter, ignore it. - } - } - if (mapExtraPropertiesAttribute != null) - { - MapExtraProperties( - sourceHasExtraProperties, - destinationHasExtraProperties, - destinationExtraProperty, - mapExtraPropertiesAttribute.DefinitionChecks, - mapExtraPropertiesAttribute.IgnoredProperties, - mapExtraPropertiesAttribute.MapToRegularProperties - ); - } + MapExtraProperties( + sourceHasExtraProperties, + destinationHasExtraProperties, + destinationExtraProperty, + mapExtraPropertiesAttribute?.DefinitionChecks ?? MappingPropertyDefinitionChecks.Null, + mapExtraPropertiesAttribute?.IgnoredProperties, + mapExtraPropertiesAttribute?.MapToRegularProperties ?? false + ); } 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 512f98f909..19bc24904e 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 @@ -84,7 +84,6 @@ public class ExtraProperties_Dictionary_Reference_Tests : AbpIntegratedTest { public override partial TestEntityDtoWithExtraProperties Map(TestEntityWithExtraProperties source); @@ -78,7 +77,6 @@ public partial class TestEntityWithExtraPropertiesMapper : MapperBase { public override partial TestEntityWithReadonlyExtraProperties Map(TestEntityWithReadonlyExtraProperties source);