如何在为每个参数使用映射器时通过构造函数构造目标类型?

时间:2016-04-29 15:09:44

标签: automapper

有没有办法在为每个参数使用映射器时映射构造函数。例如,如果我有一个dto

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

和命令

   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;}
  }

我根据后缀设置了自动化,例如   RegulatoryBodyId映射到RegualtoryBody实例,

如果我在公共命令上创建属性,那我就全都工作了,这不是我想要的。

我想要的是让automapper使用构造函数,并且在源代码上看到我有ClientId,在构造函数中我有一个Client实例,所以使用map来映射int => typeInstance。对于不在构造函数中的所有其他成员使用属性映射。这可能吗?

重新审视以下作品

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

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

我想要的是根据配置文件中定义的后缀将其应用于构造函数中的每个匹配成员。

1 个答案:

答案 0 :(得分:0)

截至目前,这不受支持。我在GH#1253 /

中提出了一个问题
相关问题