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 71b3661303..c2b830b22f 100644 --- a/framework/src/Volo.Abp.Mapperly/Volo/Abp/Mapperly/MapperlyAutoObjectMappingProvider.cs +++ b/framework/src/Volo.Abp.Mapperly/Volo/Abp/Mapperly/MapperlyAutoObjectMappingProvider.cs @@ -236,13 +236,34 @@ public class MapperlyAutoObjectMappingProvider : IAutoObjectMappingProvider protected virtual void TryMapExtraProperties(MapExtraPropertiesAttribute? mapExtraPropertiesAttribute, TSource source, TDestination destination, ExtraPropertyDictionary destinationExtraProperty) { - if (mapExtraPropertiesAttribute != null && - typeof(IHasExtraProperties).IsAssignableFrom(typeof(TDestination)) && - typeof(IHasExtraProperties).IsAssignableFrom(typeof(TSource))) + if(source is not IHasExtraProperties sourceHasExtraProperties) + { + return; + } + + if (destination is not IHasExtraProperties destinationHasExtraProperties) + { + 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( - source!.As(), - destination!.As(), + sourceHasExtraProperties, + destinationHasExtraProperties, destinationExtraProperty, mapExtraPropertiesAttribute.DefinitionChecks, mapExtraPropertiesAttribute.IgnoredProperties,