Simple high performance flat object mapper based on emitting CIL code.
It perform mapping by properties names and assignable types.
PM> Install-Package Photosphere.Mapping
This tiny library gives next extension methods
void MapTo<TSource, TTarget>(this TTarget target, TSource source); // Map from existent object to another one
void MapToObject(this object target, object source); // Map from existent object to another one
TTarget Map<TSource, TTarget>(this TSource source); // Map from existent object to new object
TTarget MapObject<TTarget>(this object source); // Map from existent object to new object
Map object source
to existent object target
source.MapTo(target);
Map object source
of type Foo
to new object target
of type Bar
var target = source.Map<Foo, Bar>();
You can perform mapping from anonymous type
var source = new { A = "a", B = 1 };
source.MapToObject(target);
or
var source = new { A = "a", B = 1 };
var target = source.MapObject<Bar>();
but not vice versa (to anonymous type object), because anonymous type objects are immutable by design.
You can see perfomance test and pefromance test result.