It would be good to map an extra property of an object to a normal property of another object.
Configuration
We can specify it on object property extension configuration:
ObjectExtensionManager.Instance
.AddOrUpdateProperty<IdentityUser, string>(
"SocialSecurityNumber",
options =>
{
options.AutoMapToNormalProperty = true; // `false` by default
});
options.MappingToNormalProperty values:
true: Maps to normal property on the target/source object if there is a matching normal property.
false: Do not maps to normal property on the target/source object by default (unless we use [MapExtraProperty] on the target class property).
We can also define an attribute, like [MapExtraProperty]:
public class MyPersonDto
{
...
[MapExtraProperty]
public string SocialSecurityNumber { get; set; }
...
}
MapExtraProperty attribute can get a property name if we want to map to another extra property name:
public class MyPersonDto
{
...
[MapExtraProperty("SocialSecurityNo")]
public string SocialSecurityNumber { get; set; }
...
}
If we defined [MapExtraProperty], it maps even if options.AutoMapToNormalProperty was false.
Implementation notes
- We currently have
MapExtraPropertiesTo() extension method (in the HasExtraPropertiesObjectExtendingExtensions class) and a corresponding MapExtraProperties() method (in the AbpAutoMapperExtensibleObjectExtensions class). That's the points we want to support this new feature. However, these extension methods are working with IHasExtraProperties objects. But actually, destination object may not be an extensible object with that new feature. So, we should try to discard that limitation if possible.
AbpAutoMapperExtensibleObjectExtensions.MapExtraProperties already has a mapToRegularProperties option. So, we should think how we can make these two system works well together.
It would be good to map an extra property of an object to a normal property of another object.
Configuration
We can specify it on object property extension configuration:
options.MappingToNormalPropertyvalues:true: Maps to normal property on the target/source object if there is a matching normal property.false: Do not maps to normal property on the target/source object by default (unless we use[MapExtraProperty]on the target class property).We can also define an attribute, like
[MapExtraProperty]:MapExtraPropertyattribute can get a property name if we want to map to another extra property name:If we defined
[MapExtraProperty], it maps even ifoptions.AutoMapToNormalPropertywasfalse.Implementation notes
MapExtraPropertiesTo()extension method (in theHasExtraPropertiesObjectExtendingExtensionsclass) and a correspondingMapExtraProperties()method (in theAbpAutoMapperExtensibleObjectExtensionsclass). That's the points we want to support this new feature. However, these extension methods are working withIHasExtraPropertiesobjects. But actually, destination object may not be an extensible object with that new feature. So, we should try to discard that limitation if possible.AbpAutoMapperExtensibleObjectExtensions.MapExtraPropertiesalready has amapToRegularPropertiesoption. So, we should think how we can make these two system works well together.