Derived types single configuration for base type configurations
See original GitHub issuehttps://github.com/riok/mapperly/issues/330 / https://github.com/riok/mapperly/pull/366 added support for derived type mappings. As of now, if a property needs a configuration on the base type (eg. MapProperty
) it needs to be done for each individual type. The configuration could be simplified a lot, when the configuration could happen on the base type method.
Classes:
abstract class Car { public int Age { get; set; } }
class Audi : Car {}
class Porsche : Car {}
abstract class CarDto { public int Age2 { get; set; } }
class AudiDto : CarDto {}
class PorscheDto : CarDto {}
Configuration on base type mapping method:
[Mapper]
public static partial class ModelMapper
{
[MapDerivedType<Audi, AudiDto>]
[MapDerivedType<Porsche, PorscheDto>]
[MapProperty("Age", "Age2")] // this does not work here...
public static partial CarDto MapCar(Car source);
}
Current required configuration:
[Mapper]
public static partial class ModelMapper
{
[MapDerivedType<Audi, AudiDto>]
[MapDerivedType<Porsche, PorscheDto>]
public static partial CarDto MapCar(Car source);
[MapProperty("Age", "Age2")]
private static partial PorscheDto MapPorsche(Porsche source);
[MapProperty("Age", "Age2")]
private static partial AudiDto MapPorsche(Audi source);
}
Issue Analytics
- State:
- Created 5 months ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
When working base and derived classes what is the best ...
Include your configuration service in your base class, then each derived class can pull their values as needed. You can now test any...
Read more >Inheritance - EF Core
Properties that belong solely to a base type or derived type are stored in a table that maps to that type. Tables that...
Read more >Mapping Class Inheritance Hierarchies
Single -table inheritance configuration looks much like joined-table inheritance, except only the base class specifies __tablename__ .
Read more >Configuration — transformers 4.10.1 documentation
Base class for all configuration classes. Handles a few parameters common to all models' configurations as well as methods for loading/downloading/saving ...
Read more >Handling Different Parameters for Derived Classes
So, I'm thinking to define struct BaseClassParams and basically include everything that derived classes need into it and simply pass the param ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@latonz Yeah I just bumped into it naturally using the ‘next’ release, so I imagine anyone using derived mappings will run into it pretty quickly
🎉 This issue has been resolved in version 3.0.0 🎉
The release is available on:
v3.0.0
Your semantic-release bot 📦🚀