Skip to content

Latest commit

 

History

History
46 lines (41 loc) · 1.98 KB

README.md

File metadata and controls

46 lines (41 loc) · 1.98 KB

Photosphere.Mapping

Simple high performance flat object mapper based on emitting CIL code.
It perform mapping by properties names and assignable types.

Status

Windows build Status NuGet license

Install via NuGet

PM> Install-Package Photosphere.Mapping

Interface

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

Examples

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.

Perfomance

You can see perfomance test and pefromance test result.