0
有沒有一種方法可以通過構造函數映射每個參數的映射器。例如,如果我有一個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");
我想要的是將其應用在構造函數中所有匹配的成員,基於配置文件定義的後綴。