Skip to content

Constructor selection in reverse mode #236

@petrnymsa

Description

@petrnymsa

Is your feature request related to a problem? Please describe.

When defining mapping with reverse flag, it is not clear how "constructor" parameter is used. Consider following classes

class Source {
   final int a;
   final int b;
   
   Source(this.a, this.b);
}

class Target {
   final int a;
   final int b;

   Target(this.a, this.b);

   Target.extra(int a) => Source(a, a *2);
}

// Mapping

MapType<Source, Target>(
  constructor: 'extra',
  reverse: true
)

This mapping will generate warning

Couldn't find constructor 'extra', fall-backing to using the most fitted one instead. (Target → Source)

Which is understandable but at first might seem confusing.

Describe the solution you'd like
We can introduce reverseConstructor param which will be used in reverse mode.

  • No constructor and no reverseContructor = standard constructor selection strategy
  • Only constructor = use in both way
  • Only reverseContructor = Source -> Target uses selection strategy, Target - Source specific contructor
  • constructor and reverseContructor = each way has defined preferred constructor

Metadata

Metadata

Assignees

Labels

breakingbugSomething isn't workingenhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions