-
-
Notifications
You must be signed in to change notification settings - Fork 201
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
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:
[AttributeUsage(AttributeTargets.Method)]
public class IncludeMappingConfigurationAttribute : Attribute
{
public IncludeMappingConfigurationAttribute(string name);
}
[AttributeUsage(AttributeTargets.Method)]
public class NamedMappingAttribute : Attribute
{
public NamedMappingAttribute(string name);
}Usage:
class Fruit { public string Name { get; set; } public decimal PricePerUnit { get; set; } }
class FruitDto { public string Title { get; set; } }
class Apple : Fruit { public int Weight { get; set; } }
class AppleDto : FruitDto { public int Weight { get; set; } }
[Mapper]
public partial static class MyMapper
{
[MapProperty(nameof(Fruit.Name), nameof(FruitDto.Title))]
[MapperIgnoreSource(nameof(Fruit.PricePerUnit))]
private partial FruitDto ToFruit(Fruit fruit);
[IncludeMappingConfiguration(nameof(ToFruit))]
public partial static AppleDto Map(Apple apple);
}hartmair, dotnetshadow, SommerEngineering, o-ric, faddiv and 2 morer365bdelamare, mpickers and SommerEngineeringSommerEngineering
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request