Open latonz opened 1 year ago
What if the (named) mapping configuration is defined in another (different) Mapping class? (Happens a lot in my projects.)
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 bool Reverse
and on existing target instance mappings.
What is the current guidance to work around this issue since the attribute isn't available. Would you advise passing in the mapper as a property to other mappers?
For the example public partial static AppleDto Map(Apple apple);
currently nothing would be automatically mapped since Mapperly doesn't know that a mapper exists for this is that correct?
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 applyingIncludeMappingConfigurationAttribute
:[IncludeMappingConfiguration("myName")]
/[IncludeMappingConfiguration(nameof(OtherMappingMethod))]
. If anIncludeMappingConfigurationAttribute
references an ambiguous mapping configuration, a diagnostic should be emitted.Proposed API:
Usage: