Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Support From and To static factory methods #1117

@TimothyMakkison

Description

@TimothyMakkison

Is your feature request related to a problem? Please describe.
Many objects provide static methods instead of constructors for semantic reasons. Unfortunately as Mapperly is unable to use them users have to manually provide wrapper methods. Based upon.

Solution

Mapperly should look for static methods that meet the following criteria:

  • static methods on the target type named From{SourceType.Name} accepting the source type as a single parameter and the target type as return type
  • static methods on the source type named To{TargetType.Name} accepting the source type as single parameter returning the target type

Implementation

  • This should be used as a fallback for if there are no compatible constructors. Should look for the target types From methods before looking for the source To methods.
  • Perhaps the sources To methods could include non static methods.
var target = new global::Mapperly_gRPC.HelloReply();
target.Message = response.Message;
target.ResponseTime = Timestamp.FromDateTimeOffset(response.ResponseTime);
return target;

See #1107.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions