0

私は以下のクラスを持っています

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;  

}

SourceクラスからDestinationクラスへの自動マップを実行したいと考えています。私が見る課題は、連絡先番号のリストを宛先クラスの独立したフィールドに変換することです。誰でも方法を提案できますか?前もって感謝します。

4

1 に答える 1

0

シンプルで読みやすいカスタム マッピング関数を使用するのがおそらく最も簡単です。

CreateMap<Contact, Destination>().ConvertUsing(c => MapContactToDestination(c));

Destination MapContactToDestination(Contact c)
{
    //logic here for handling conversion
}
于 2013-03-14T11:02:34.417 に答える