By default:
- Writable fields and properties, single-parameter methods prefixed with 'Set', constructor parameters and non-null, readonly complex type or enumerable members (except arrays) are targeted
- Target members are matched to compatibly-typed source members by name
- Source members prefixed with 'Get' are matched without the prefix -
GetHashCodeandGetTypeare ignored - Members named
Id,<Type name>Id,Identifieror<Type name>Identifierare matched - Target members with no compatible source member are ignored.
- Target members with the same name as a constructor parameter are ignored (because we assume the constructor will populate them)
For example:
public class CustomerViewModel
{
public string Name { get; set; }
public string Id { get; set; }
public string HomeAddressLine1 { get; set; }
public string WorkAddressLine1 { get; set; }
public byte[] Data { get; set; }
}
public class Customer
{
public string Name;
public Guid CustomerId { get; set; }
public Address HomeAddress { get; set; }
public Address WorkAddress { get; }
public void SetData(DateTime value) {}
}
public class Address
{
public string Line1 { get; set; }
}
When mapping CustomerViewModel to Customer:
Customer.Nameis populated usingCustomerViewModel.Name- The
Customer.CustomerIdGuid is populated using the parsedCustomerViewModel.Idstring Customer.HomeAddressis populated with a newAddressinstance if one does not already existCustomer.HomeAddress.Line1is populated usingCustomerViewModel.HomeAddressLine1Customer.WorkAddressis get-only, so is ignored if it's nullCustomer.WorkAddress.Line1is populated usingCustomerViewModel.WorkAddressLine1Customer.SetData(DateTime value)is ignored, because its match -CustomerViewModel.Data- is abyte[], which cannot be parsed to aDateTime
When mapping from Customer to CustomerViewModel, the matches are made in the opposite direction.