using System.Collections.Generic;
public static void Main()
dynamic personDto = new PersonDto();
personDto.Name = "The Value";
var config = new MapperConfiguration(cfg =>
cfg.CreateMap<PersonDto, OfficePersonDto>()
.ForMember(d => d.Name, opt => opt.MapFrom(new DynamicObjectValueResolver<PersonDto, OfficePersonDto, string>("name")));
var mapper = config.CreateMapper();
var off = mapper.Map<OfficePersonDto>(personDto);
Console.WriteLine("Id is: " + off.Id);
Console.WriteLine("Name is: " + off.Name);
public class DynamicObjectValueResolver<TSource, TDestination, TDestinationMember> : IValueResolver<TSource, TDestination, TDestinationMember>
where TDestinationMember : class
private readonly string _propertyName;
public DynamicObjectValueResolver(string propertyName)
_propertyName = propertyName;
public TDestinationMember Resolve(TSource source, TDestination destination, TDestinationMember destMember, ResolutionContext context)
dynamic eo = JsonConvert.DeserializeObject<ExpandoObject>(JsonConvert.SerializeObject(source));
IDictionary<string, object> dictionary = eo;
return dictionary[_propertyName] as TDestinationMember;
public class PersonDto : DocumentObject
public string Id { get; set; }
public class OfficePersonDto : PersonDto
public string Name { get; set; }
public class DocumentObject : DynamicObject
Dictionary<string, object> dictionary = new Dictionary<string, object>();
public override bool TryGetMember(GetMemberBinder binder, out object result)
string name = binder.Name.ToLower();
return dictionary.TryGetValue(name, out result);
public override bool TrySetMember(SetMemberBinder binder, object value)
dictionary[binder.Name.ToLower()] = value;
public override IEnumerable<string> GetDynamicMemberNames()