需要自动执行建议



我有以下类

class Contact  
{  
  string FirstName;  
  string LastName;  
  List<Phone> ContactNumbers;  
}
class Phone  
{  
  string Number;  
  PhoneType Type;  
}  
enum PhoneType  
{  
  Home, Work, Fax
}  
class Source
{
  Contact Agent;
  Contact Customer;
}
class Destination  
{  
  string AgentFirstName;  
  string AgentLastName;  
  string AgentPhoneNumber1;  
  string AgentPhoneNumber2;  
  string AgentPhoneNumber3;  
  PhoneType AgentPhoneType1;  
  PhoneType AgentPhoneType2;  
  PhoneType AgentPhoneType3; 
  string CustomerFirstName;  
  string CustomerLastName;  
  string CustomerPhoneNumber1;  
  string CustomerPhoneNumber2;  
  string CustomerPhoneNumber3;  
  PhoneType CustomerPhoneType1;  
  PhoneType CustomerPhoneType2;  
  PhoneType CustomerPhoneType3;  
}

我想做自动映射从目的地类。我看到的挑战是将联系人号码列表转换为目的地类中的独立字段。谁能告诉我怎么走?提前感谢。

做一个自定义映射函数可能是最简单的,它使事情简单易读:

CreateMap<Contact, Destination>().ConvertUsing(c => MapContactToDestination(c));
Destination MapContactToDestination(Contact c)
{
    //logic here for handling conversion
}

相关内容

  • 没有找到相关文章

最新更新