-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Open
Milestone
Description
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 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.