abpframework / abpframework/abp

Extra property to Normal property mapping for extensible objects.

Open
#3,478 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

abp-framework effort-sm feature
Dominant language
C#
Stars
14.4k
Forks
3.7k
Avg merge
15h 32m
Merged PRs (30d)
106

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 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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with MapExtraPropertiesTo() in HasExtraPropertiesObjectExtendingExtensions and MapExtraProperties() in AbpAutoMapperExtensibleObjectExtensions. Review the existing mapToRegularProperties option, then define how AutoMapToNormalProperty and MapExtraProperty should interact; done means matching or explicitly renamed extra properties map correctly even when the destination is not extensible.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.