-
Notifications
You must be signed in to change notification settings - Fork 1
Conversions
JulianR edited this page Mar 18, 2012
·
1 revision
Added in 1.3.0 was the ability to add general mapping rules, allowing you to specify your own conversions.
An example:
private void ApplyMappingOptions(PropertyOrFieldInfo source, PropertyOrFieldInfo dest, MemberOption options, int depth)
{
if(source.PropertyOrFieldType == typeof(DateTime))
{
options.Convert<DateTime, DateTime>(d => d.ToUniversalTime());
}
}
var mapper = new MemberMapper();
mapper.CreateMap<Customer, CustomerDto>(options: ApplyMappingOptions);
var result = mapper.Map(customer, new CustomerDto());
Assert.AreEqual(DateTimeKind.Utc, result.CreationTime.Kind); // will be true
As you can see, the API is rather simple and self explanatory.