question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Derived types single configuration for base type configurations

See original GitHub issue

https://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:closed
  • Created 5 months ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
onionhammercommented, Jun 9, 2023

@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

0reactions
github-actions[bot]commented, Aug 7, 2023

🎉 This issue has been resolved in version 3.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Read more comments on GitHub >

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

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found