Basic usage

Like most mappers, Mapster can do its job in a number of different and convenient ways.

Let's start with the most basic usage, where a source object can be directly mapped to a destination object:

var destObject = sourceObject.Adapt<TDestination>();

Alternatively, we can instantiate a mapper by ourselves (or get it through Dependency Injection):

IAdapter adapter = new Adapter();var destObject = adapter.Adapt<TDestination>(sourceObject);

All achieve the same result using a static method:

var destObject = TypeAdapter.Adapt<TDestination>;

All mappings can be either configured on-the-fly--during the mapping itself--or globally, using the TypeAdapterConfig static class, which also features a fluent and readable syntax:

TypeAdapterConfig<TSource, ...

Get ASP.NET Core 2 and Angular 5 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.