Skip to content

Instantly share code, notes, and snippets.

@lbargaoanu
Created June 26, 2017 08:25
Show Gist options
  • Save lbargaoanu/34a397a5ced65d8d2547c4440893a0ee to your computer and use it in GitHub Desktop.
Save lbargaoanu/34a397a5ced65d8d2547c4440893a0ee to your computer and use it in GitHub Desktop.
public void Main()
{
Mapper.Initialize(cfg =>
{
cfg.CreateMap<ExpandoObject, Destination>().ConvertUsing((expando, destination, context)=>
{
var dictionary = context.Mapper.Map<Dictionary<string,object>>(expando);
context.Mapper.Map(dictionary, destination);
// after map
return destination;
});
});
Mapper.AssertConfigurationIsValid();
dynamic source = new ExpandoObject();
source.Id = 34;
source.Name = "thirty four";
var dest = new Destination();
Mapper.Map(source, dest);
dest.Dump();
}
class Destination
{
public int Id { get; set; }
public string Name { get; set; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment