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, TDestination>
.NewConfig()
.Ignore(dest => dest.IgnoreThisProperty)
.Map(dest => dest.MergeProperty1And2,
src => string.Format("{0}{1}", src.Property1, src.Property2));

However, where Mapster really shines is the speed. Arguably 2.5 times faster than AutoMapper, it's twice as fast as other better known alternatives out there.

Those who want to know more about Mapster and how to use it are encouraged to visit the official project repo on GitHub at https://github.com/chaowlert/Mapster.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.201.217