Skip to content

Recognize pre/postfixes in ctor args #1253

@epitka

Description

@epitka

As per user group I am opening this as a improvement request.

Is there a way to map through a constructor while using a mappers for each of the parameters. For example if I have a dto

   public class CreateBid
   {
      public int ClientId { get; set; }
      public int RegulatoryBodyId {get;set;}
      public string Descripption {get;set;
    }

and command

   public class CreateBidCommand
   {
      public CreateBidCommand(Client client, 
             RegulatoryBody regulatoryBody, string description)
      {
           Client = client;
           RegulatoryBody = regulatoryBody;
           Description = description;
      }

      public Client Client {get;}
      public RegulatoryBody RegulatoryBody {get;}
      public string Description {get;}
  }

and I have setup automapping based on the suffix so that for example RegulatoryBodyId is mapped to instance RegualtoryBody,

I have all working if I make properties on my command public, which is not what I want.

What I want is for automapper to use constructor, and see that on source I have ClientId, in constructor I have a instance of Client, so use map to map int=>typeInstance. For all other members that are not in constructor use property mapping. Is this possible?

Just to re-iterate following works

_mapper.Map<int,Client>(112313);
or

_mapper.Map<string,SomeType>("someCode");

What I want is to apply this to every matching member in the constructor, based on the suffixes defined in the profile.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions