-
-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include mapping configuration #513
Comments
What if the (named) mapping configuration is defined in another (different) Mapping class? Will/should it work anyway? |
@mutzl it will work as long as it is in the same project and via explicit name. We could probably also add a constructor overload to include the mapper type and generate the name based on the name of the mapper + the name of the mapping method. |
Being able to reuse mappings from a base type would be critical for a number of usecases we have |
This should also work for reverse mappings with an additional property |
What is the current guidance to work around this issue since the attribute isn't available. For the example |
@latonz What's the status of this feature? I would really need this for scenarios that involve inheritance. Example: public partial PositionDTO Map(Position source);
[MapProperty(nameof(MassPosition.Mass), nameof(MassPositionDTO.MassInInputUnit))]
public partial MassPositionDTO Map(MassPosition source);
[MapProperty(nameof(@DurationPosition.Duration.Hours), nameof(DurationPositionDTO.DurationInH))]
public partial DurationPositionDTO Map(DurationPosition source);
// ShaftSealingPosition derives from MassPosition and I need to duplicate this mapping on every subtype
[MapProperty(nameof(MassPosition.Mass), nameof(MassPositionDTO.MassInInputUnit))]
public partial ShaftSealingPositionDTO Map(ShaftSealingPosition source);
|
This hasn‘t been implemented yet and also no one is currently working on this. Feel free to contribute. There is no real workaround, except to duplicate your configuration. |
Introduce two new attributes to include the mapping configuration of another mapper / mapping method.
Each mapping configuration is identified by a name which is by default the name of the method, but can be overwritten by
NamedMappingAttribute
, eg.[NamedMapping("myName")]
.A mapping configuration can be applied to the current mapping method by applying
IncludeMappingConfigurationAttribute
:[IncludeMappingConfiguration("myName")]
/[IncludeMappingConfiguration(nameof(OtherMappingMethod))]
.If an
IncludeMappingConfigurationAttribute
references an ambiguous mapping configuration, a diagnostic should be emitted.Proposed API:
Usage:
The text was updated successfully, but these errors were encountered: