Browse Source

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.
pull/23689/head
SALİH ÖZKARA 1 year ago
parent
commit
d8f5012a2b
  1. 32
      framework/src/Volo.Abp.Mapperly/Volo/Abp/Mapperly/MapperlyAutoObjectMappingProvider.cs
  2. 1
      framework/test/Volo.Abp.Mapperly.Tests/Volo/Abp/Mapperly/ExtraProperties_Dictionary_Reference_Tests.cs
  3. 2
      framework/test/Volo.Abp.Mapperly.Tests/Volo/Abp/Mapperly/SampleClasses/MapperlyMappers.cs

32
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<TSource, TDestination>(
sourceHasExtraProperties,
destinationHasExtraProperties,
destinationExtraProperty,
mapExtraPropertiesAttribute.DefinitionChecks,
mapExtraPropertiesAttribute.IgnoredProperties,
mapExtraPropertiesAttribute.MapToRegularProperties
);
}
MapExtraProperties<TSource, TDestination>(
sourceHasExtraProperties,
destinationHasExtraProperties,
destinationExtraProperty,
mapExtraPropertiesAttribute?.DefinitionChecks ?? MappingPropertyDefinitionChecks.Null,
mapExtraPropertiesAttribute?.IgnoredProperties,
mapExtraPropertiesAttribute?.MapToRegularProperties ?? false
);
}
protected virtual void MapExtraProperties<TSource, TDestination>(
IHasExtraProperties source,

1
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<Mapp
destination.SetProperty("DestinationProperty", "DestinationValue");
var originalSourceReference = source.ExtraProperties;
var originalDestinationReference = destination.ExtraProperties;
// Verify they have different references before mapping
ReferenceEquals(source.ExtraProperties, destination.ExtraProperties).ShouldBeFalse();

2
framework/test/Volo.Abp.Mapperly.Tests/Volo/Abp/Mapperly/SampleClasses/MapperlyMappers.cs

@ -69,7 +69,6 @@ public class TestEntityWithReadonlyExtraProperties : IHasExtraProperties
}
[Mapper]
[MapExtraProperties]
public partial class TestEntityWithExtraPropertiesMapper : MapperBase<TestEntityWithExtraProperties, TestEntityDtoWithExtraProperties>
{
public override partial TestEntityDtoWithExtraProperties Map(TestEntityWithExtraProperties source);
@ -78,7 +77,6 @@ public partial class TestEntityWithExtraPropertiesMapper : MapperBase<TestEntity
}
[Mapper]
[MapExtraProperties]
public partial class TestEntityWithReadonlyExtraPropertiesMapper : MapperBase<TestEntityWithReadonlyExtraProperties, TestEntityWithReadonlyExtraProperties>
{
public override partial TestEntityWithReadonlyExtraProperties Map(TestEntityWithReadonlyExtraProperties source);

Loading…
Cancel
Save